Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Q1.py
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 4 additions & 0 deletions Q2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import string
char = list(string.ascii_uppercase)
for i in range(len(char)):
open(f"{char[i]}.txt", 'x')
22 changes: 22 additions & 0 deletions Q3.py
Original file line number Diff line number Diff line change
@@ -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)
Binary file added Q4/__pycache__/addition.cpython-311.pyc
Binary file not shown.
Binary file added Q4/__pycache__/division.cpython-311.pyc
Binary file not shown.
Binary file added Q4/__pycache__/multiplication.cpython-311.pyc
Binary file not shown.
Binary file added Q4/__pycache__/subtraction.cpython-311.pyc
Binary file not shown.
3 changes: 3 additions & 0 deletions Q4/addition.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
def add(n1,n2):
result = n1+n2
return result
3 changes: 3 additions & 0 deletions Q4/division.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
def div(n1, n2):
result = n1/n2
return result
47 changes: 47 additions & 0 deletions Q4/main.py
Original file line number Diff line number Diff line change
@@ -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'")
3 changes: 3 additions & 0 deletions Q4/multiplication.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
def multi(n1, n2):
result = n1*n2
return result
3 changes: 3 additions & 0 deletions Q4/subtraction.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
def sub(n1, n2):
result = n1-n2
return result