diff --git a/Q1.py b/Q1.py new file mode 100644 index 0000000..b587443 --- /dev/null +++ b/Q1.py @@ -0,0 +1,8 @@ +import string + +n = int(input("Enter the number of letters in each line:")) +with open("letters.txt", "w") as f: + alphabet = string.ascii_letters + for i in range(0, len(alphabet), n): + letters = [alphabet[i:i + n] + "\n"] + f.writelines(letters) diff --git a/Q2.py b/Q2.py new file mode 100644 index 0000000..872a7e9 --- /dev/null +++ b/Q2.py @@ -0,0 +1,4 @@ +import string +char = list(string.ascii_uppercase) +for i in range(len(char)): + open(f"{char[i]}.txt", 'x') diff --git a/Q3.py b/Q3.py new file mode 100644 index 0000000..f6af8dc --- /dev/null +++ b/Q3.py @@ -0,0 +1,22 @@ +from math import gcd +from functools import reduce + + +def lcm_function(list): + return reduce(lambda a, b: a * b // gcd(a, b), list) + + +list = [] +for i in range(1, 5): + try: + num = int(input(f"Enter number {i} : ")) + num != None + list.append(num) + + except ValueError: + print("Value can't be empty or non numerical") + exit() + +print(list) +result = lcm_function(list) +print("The L.C.M is :", result) diff --git a/Q4/__pycache__/addition.cpython-311.pyc b/Q4/__pycache__/addition.cpython-311.pyc new file mode 100644 index 0000000..78dea82 Binary files /dev/null and b/Q4/__pycache__/addition.cpython-311.pyc differ diff --git a/Q4/__pycache__/division.cpython-311.pyc b/Q4/__pycache__/division.cpython-311.pyc new file mode 100644 index 0000000..5dd8c42 Binary files /dev/null and b/Q4/__pycache__/division.cpython-311.pyc differ diff --git a/Q4/__pycache__/multiplication.cpython-311.pyc b/Q4/__pycache__/multiplication.cpython-311.pyc new file mode 100644 index 0000000..9afb799 Binary files /dev/null and b/Q4/__pycache__/multiplication.cpython-311.pyc differ diff --git a/Q4/__pycache__/subtraction.cpython-311.pyc b/Q4/__pycache__/subtraction.cpython-311.pyc new file mode 100644 index 0000000..1700f36 Binary files /dev/null and b/Q4/__pycache__/subtraction.cpython-311.pyc differ diff --git a/Q4/addition.py b/Q4/addition.py new file mode 100644 index 0000000..43cae1a --- /dev/null +++ b/Q4/addition.py @@ -0,0 +1,3 @@ +def add(n1,n2): + result = n1+n2 + return result \ No newline at end of file diff --git a/Q4/division.py b/Q4/division.py new file mode 100644 index 0000000..cb26248 --- /dev/null +++ b/Q4/division.py @@ -0,0 +1,3 @@ +def div(n1, n2): + result = n1/n2 + return result diff --git a/Q4/main.py b/Q4/main.py new file mode 100644 index 0000000..81fcaba --- /dev/null +++ b/Q4/main.py @@ -0,0 +1,47 @@ +import math +from addition import add +from subtraction import sub +from multiplication import multi +from division import div + + +i = "Y" +while i == "Y": + while True: + try: + num1 = float(input("\nEnter the first number:")) + num2 = float(input("Enter the second number:")) + break + except ValueError: + print("Value can't be empty or non numerical") + + print( + "\nSelect operation:(You can select by pressing the number next to the operation)") + print("1-Addition\n2-Subtraction\n3-Multiplication\n4-Divison\n") + while True: + try: + select = int(input("Enter your choice:")) + assert select in [1, 2, 3, 4] + break + except: + print( + "Invalid input, Value can't be empty or non numerical, Make sure you select the correct number of the operation" + ) + + if select == 1: + result = add(num1, num2) + elif select == 2: + result = sub(num1, num2) + elif select == 3: + result = multi(num1, num2) + else: + result = div(num1, num2) + + print("\nThe result is:", math.ceil(result)) + while True: + try: + i = input("\nPress 'Y to continue or 'N to exit': ").upper() + assert i in ["Y", "N"] + break + except: + print("Please enter either 'Y' or 'N'") diff --git a/Q4/multiplication.py b/Q4/multiplication.py new file mode 100644 index 0000000..83f5813 --- /dev/null +++ b/Q4/multiplication.py @@ -0,0 +1,3 @@ +def multi(n1, n2): + result = n1*n2 + return result diff --git a/Q4/subtraction.py b/Q4/subtraction.py new file mode 100644 index 0000000..a0303ec --- /dev/null +++ b/Q4/subtraction.py @@ -0,0 +1,3 @@ +def sub(n1, n2): + result = n1-n2 + return result