Skip to content

Commit 997ae14

Browse files
committed
commit all scripts
1 parent 221b9ba commit 997ae14

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1409
-0
lines changed

.ipynb_checkpoints/STLD-checkpoint.xml

+1
Large diffs are not rendered by default.

.ipynb_checkpoints/robust_xml_parser-checkpoint.ipynb

+537
Large diffs are not rendered by default.

__pycache__/config.cpython-311.pyc

488 Bytes
Binary file not shown.
476 Bytes
Binary file not shown.

__pycache__/myScript.cpython-311.pyc

383 Bytes
Binary file not shown.
551 Bytes
Binary file not shown.

alpha_to_number.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
""" Python Challenge:
2+
how to convert alphabets to
3+
numbers using the A1Z26 cipher
4+
"""
5+
def alpha_to_numbers(alphabets):
6+
numbers = []
7+
8+
for letter in alphabets.replace(' ', ''):
9+
number = ord(letter.upper()) - ord('A') + 1
10+
numbers.append(number)
11+
12+
return numbers
13+
14+
# test the function
15+
alphabets = 'epython lab'
16+
# numbers = [5, 16, 25, 20, 8, 15, 14, 12, 1, 2]
17+
18+
print(alpha_to_numbers(alphabets))

binary_decimal.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"""
2+
Python Challenge:
3+
Convert binary to decimal
4+
"""
5+
def binary_to_decimal(binary):
6+
return int(binary, 2)
7+
"""
8+
def binary_to_decimal(binary):
9+
decimal = 0
10+
power = 0
11+
while binary != 0:
12+
decimal += (binary % 10) * (2 ** power)
13+
binary //= 10
14+
power += 1
15+
return decimal
16+
"""
17+
18+
# test the function
19+
binary = '11'
20+
decimal = binary_to_decimal(binary)
21+
print(decimal) # output: 3
22+
23+

binary_list.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
"""
2+
Python Challenge:
3+
Binary number to List
4+
"""
5+
def binaryList(binary):
6+
binary_list = []
7+
8+
for i in list(str(binary)):
9+
binary_list.append(int(i))
10+
return binary_list
11+
12+
# test the function
13+
binary = int(input('Enter binary number:'))
14+
# input: 10011
15+
binary_list = binaryList(binary)
16+
print(binary_list)
17+
# output: [1, 0, 0, 1, 1]
18+

check_file.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"""
2+
how to check if file exists
3+
in Python
4+
"""
5+
import os
6+
def is_file_exists(file_path):
7+
return os.path.exists(file_path)
8+
9+
# test the function
10+
file_path = 'main.py'
11+
if is_file_exists(file_path):
12+
print('The file exists.')
13+
else:
14+
print('The file does not exist')
15+

continue_break.py

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"""
2+
Break.
3+
For example, the following code will print
4+
the numbers from 1 to 5,
5+
but it will break out of the loop if the number is 3:
6+
"""
7+
8+
for i, num in enumerate(range(1,6)):
9+
if num == 3:
10+
break
11+
print(f'{i}. {num}')
12+
13+
# 0. 1
14+
# 1. 2
15+
16+
17+
18+
"""
19+
Continue...
20+
For example,
21+
the following code will print
22+
the even numbers from 1 to 10,
23+
24+
But the if statement checks if the current number is even.
25+
If it is even, the print statement prints the number.
26+
If it is not even,
27+
the continue statement skips the current iteration of the loop
28+
and goes to the next iteration.:
29+
"""
30+
for i, num in enumerate(range(2, 11)):
31+
if num % 2 == 0:
32+
print(f'{i}. {num}')
33+
else:
34+
break

cpp_generator.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import pandas as pd
2+
3+
df1 = pd.DataFrame.from_dict({"A": ["x", "y", "z", "w"], "B": ["i", "j", "k", "l"]})
4+
df2 = pd.DataFrame.from_dict({"C": ["w", "t", "s", "x"], "D": ["n", "y", "z", "m"], "E": [1, 2, 3, 4]})
5+
6+
df3 = df1.merge(df2[['C', 'E']], left_on='A', right_on='B', how='left')
7+
df3.drop('C', axis=1, inplace=True)
8+
9+
df3['E'] = df3['E'].fillna(df2['E'])
10+
11+
print(df3)

data/cpp.json

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"class_name": "Person",
3+
"header_file": "person.h",
4+
"source_file": "person.cpp",
5+
"properties": [
6+
{
7+
"name": "name",
8+
"type": "std::string"
9+
},
10+
{
11+
"name": "age",
12+
"type": "int"
13+
},
14+
{
15+
"name": "height",
16+
"type": "double"
17+
}
18+
]
19+
}
20+

data/output.cpp

Whitespace-only changes.

data/template.cpp

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// {header_file}
2+
3+
#include <iostream>
4+
#include <string>
5+
6+
class {class_name} {
7+
public:
8+
// Constructor
9+
{class_name}() {}
10+
11+
// Getters and setters
12+
{property_getters_setters}
13+
14+
private:
15+
{property_declarations}
16+
};
17+
18+
// Getters
19+
{property_getters}
20+
21+
// Setters
22+
{property_setters}
23+
24+
int main() {
25+
// Create an instance of {class_name}
26+
{class_name} obj;
27+
28+
// Use getters and setters
29+
obj.set{name}("John Doe");
30+
obj.set{age}(30);
31+
obj.set{height}(1.75);
32+
33+
std::cout << "Name: " << obj.get{name}() << std::endl;
34+
std::cout << "Age: " << obj.get{age}() << std::endl;
35+
std::cout << "Height: " << obj.get{height}() << std::endl;
36+
37+
return 0;
38+
}

days_to_months.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"""
2+
Python Challenge:
3+
Convert Integer to times
4+
"""
5+
from datetime import datetime
6+
# create list of integers
7+
numbers = [930, 1215, 1500, 1850]
8+
# convert to times
9+
times = []
10+
for num in numbers:
11+
num_str = str(num)
12+
time_ob = datetime.strptime(
13+
num_str, '%H%M')
14+
time_formatted = time_ob.strftime('%H:%M')
15+
times.append(time_formatted)
16+
17+
# print converted times
18+
print(*times, sep='\n')
19+
20+

decimal_binary.py

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
"""Python Challenge:
2+
Converts a Decimal number to binary
3+
"""
4+
def decimal2binary(decimal_number):
5+
"""
6+
Converts a decimal number to binary
7+
using the division method.
8+
9+
Args:
10+
decimal_number: The decimal number to convert.
11+
12+
Returns:
13+
The binary representation of the decimal number.
14+
"""
15+
binary_repr = []
16+
quotient = decimal_number
17+
while quotient > 0:
18+
remainder = quotient % 2
19+
binary_repr.append(remainder)
20+
quotient = quotient // 2
21+
22+
binary_repr.reverse()
23+
24+
return binary_repr
25+
26+
# testing the code
27+
decimal_number = 75
28+
# [1, 0, 0, 1, 0, 1, 1]
29+
binary_repr = decimal2binary(decimal_number)
30+
print(binary_repr)
31+

decode_marshal.py

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from cryptography.fernet import Fernet
2+
3+
# def encrypt_file(file_path, encryption_key):
4+
# with open(file_path, 'rb') as file:
5+
# plaintext = file.read()
6+
7+
# cipher = Fernet(encryption_key)
8+
# encrypted_data = cipher.encrypt(plaintext)
9+
10+
# encrypted_file_path = file_path + '.encrypted'
11+
# with open(encrypted_file_path, 'wb') as file:
12+
# file.write(encrypted_data)
13+
14+
# return encrypted_file_path
15+
16+
def decrypt_file(encrypted_file_path, encryption_key):
17+
with open(encrypted_file_path, 'rb') as file:
18+
encrypted_data = file.read()
19+
20+
cipher = Fernet(encryption_key)
21+
decrypted_data = cipher.decrypt(encrypted_data)
22+
23+
decrypted_file_path = encrypted_file_path[:-10] # Remove the '.encrypted' extension
24+
with open(decrypted_file_path, 'wb') as file:
25+
file.write(decrypted_data)
26+
27+
return decrypted_file_path
28+
29+
# Example usage:
30+
encryption_key = Fernet.generate_key()
31+
32+
# Encrypt a Python file
33+
file_path = 'm.py'
34+
# encrypted_file_path = encrypt_file(file_path, encryption_key)
35+
# print('Encrypted file:', encrypted_file_path)
36+
37+
# Decrypt the encrypted file
38+
decrypted_file_path = decrypt_file(file_path, encryption_key)
39+
print('Decrypted file:', decrypted_file_path)

eid.py

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import turtle
2+
3+
def draw_eid_mubarak():
4+
turtle.speed("slowest") # Set the drawing speed (optional)
5+
6+
# Create turtle screen
7+
screen = turtle.Screen()
8+
screen.bgcolor("gold") # Set the background color to gold
9+
10+
# Draw "Eid"
11+
turtle.penup()
12+
turtle.goto(-200, 0)
13+
turtle.pendown()
14+
turtle.color("darkblue") # Set the text color to dark blue
15+
turtle.write("Eid", font=("Arial", 60, "bold"))
16+
17+
# Draw "Mubarak"
18+
turtle.penup()
19+
turtle.goto(-200, -100)
20+
turtle.pendown()
21+
turtle.color("darkblue") # Set the text color to dark blue
22+
turtle.write("Mubarak!", font=("Arial", 60, "bold"))
23+
24+
turtle.done()
25+
26+
if __name__ == "__main__":
27+
draw_eid_mubarak()

encoding.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"""Python Challenge:
2+
String Encoding and Decoding
3+
"""
4+
import base64
5+
6+
def encoding(string):
7+
8+
encoded = base64.b64encode(string.encode('utf-8'))
9+
10+
return encoded
11+
12+
def decoding(byte):
13+
decoded = base64.b64decode(byte).decode('utf-8')
14+
return decoded
15+
16+
# test the function
17+
string = 'epythonlab'
18+
encoded = encoding(string)
19+
print(f'Original string: {string}')
20+
print(f'Encoded: {encoded}')
21+
22+
decoded = decoding(encoded)
23+
print(f'After decoded: {decoded}')

extract_table.py

Whitespace-only changes.

factorial.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
"""
2+
Python Challenge:
3+
Efficient Factorial Calculation
4+
in Python: Optimizing Performance
5+
"""
6+
def factorial(n):
7+
if n == 0:
8+
return 1
9+
else:
10+
return n*factorial(n-1)
11+
12+
# test the function
13+
fact = factorial(5)
14+
print(fact) # 120

fibonacci.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Prints Fibonacci
2+
# Sequence
3+
def fib(n):
4+
if n == 0 or n == 1:
5+
return n
6+
else:
7+
return fib(n-1)+fib(n-2)
8+
9+
def main():
10+
n = int(input('Enter a number:'))
11+
print(f'Fibonacci sequence of {n} is:')
12+
13+
for i in range(n):
14+
print(fib(i))
15+
16+
# test the code
17+
if __name__ == '__main__':
18+
main()

get_even.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"""
2+
"Python Challenge:
3+
Extract Even Numbers from a List
4+
"""
5+
def extract_even(numbers):
6+
# your code here
7+
even_numbers = []
8+
for num in numbers:
9+
if num % 2 == 0:
10+
even_numbers.append(num)
11+
return even_numbers
12+
13+
nums = range(2, 20)
14+
print(extract_even(nums))
15+
# [2, 4, 6, 8, 10, 12, 14, 16, 18]
16+
17+
nums = range(2, 50, 5)
18+
print(extract_even(nums))
19+
# [2, 12, 22, 32, 42]
20+

gpt/pyChatBot.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import re
2+
CommonPrefixes = {'Prefix': 'JG/BMF/'}
3+
4+
result = re.split(r'/', CommonPrefixes['Prefix'])
5+
6+
print(result)

0 commit comments

Comments
 (0)