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
10 changes: 10 additions & 0 deletions 1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Question 1
import string

def letters_4_line(n):
with open("letters4line.txt", "w") as f:
alphabet1 = string.ascii_uppercase # choosing upper case
alphabet2 = string.ascii_lowercase # choosing lower case
letters_ubb_low = [alphabet1[i:i + n]+ alphabet2[i:i + n] + "\n" for i in range(0, len(alphabet1), n)]
f.writelines(letters_ubb_low)
letters_4_line(1)
6 changes: 6 additions & 0 deletions 2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Question 2
import string
import os
os.chdir('C:\\Users\\Computer\\PycharmProjects\hello\\4 week') # the direction
for alphabet in string.ascii_uppercase :
f = open(alphabet + ".txt", "w")
16 changes: 16 additions & 0 deletions 3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Question 3
# LCM question:
try:
numbers = list(map(int,input('enter four numbers for calculating LCM: ').strip().split())) #Enter the numbers here with spaces between them
numbers.sort(reverse = True)
numbers
from math import gcd # importing the 'gcd' function from the 'math' module of math to calculate the greatest common divisor
lcm = 1
for n in numbers:
lcm = lcm*n//gcd(lcm, n) # Calculating the least common multiple (L.C.M.) of the numbers
gcd()
print("The least common multiple (L.C.M.) of your four numbers is: ", lcm)
except:
print("Invalid input Error: Pleass enter integer numbers.") # warnning the user for Nan or non numerical inputs
finally:
print("It is done.")
40 changes: 40 additions & 0 deletions 4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
### Mis Calculator
from ceil_add import *
from ceil_div import *
from ceil_mult import *
from ceil_sub import *

def operation():
while True:
user_choice = input (" Enter Your choice as follows: for Summation please write = (sum), for Subtraction= (sub), for Multiplication = (mul), for Division= (div):> ").lower()
try: # Using try/except block to verify input entries and warn the user for incorrect inputs.
number_1 = float(input("Enter your first number: ")) # two parameters are float numbers
number_2 = float(input("Enter your second number: "))
except ValueError:
print("Invalid Input Error: Please enter a number!")
continue
# Check the user's choice and call the appropriate function from the imported module
if user_choice == "sum":
result = addition(number_1, number_2)
print("Summation of the two numbers is: ", result)
elif user_choice == "sub":
result = subtruction(number_1, number_2)
print("Subtruction of the two numbers is: ", result)
elif user_choice == "mul":
result = multiplication(number_1, number_2)
print("Multiplication of the two numbers is: ", result)
elif user_choice == "div":
result = division(number_1, number_2)
print("Division of the two numbers is: ", result)
# except:
# number_2 ==0
# break
# print("ZeroDivisionError because number_2 should not be zero!!! ")
else: # warnning the user for incorrect inputs.
print("You entered something wrong! Invalid choice.")
continue
calc_again = input("If you want to use the Mis Calculator again, please type upper letter of the first word Yes or No (Y/N): ").upper() # Ask the user if he/ she wants to use the calculater again
if calc_again == 'N':
break
if __name__ == "__pycache__":
operation()
5 changes: 5 additions & 0 deletions ceil_add.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Addition
from math import ceil
def addition(number_1, number_2):
sum = number_1 + number_2
return ceil(sum)
9 changes: 9 additions & 0 deletions ceil_div.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Division
from math import ceil
def division(number_1, number_2):
try:
div = number_1 / number_2
except ZeroDivisionError as e:
return e
else:
return ceil(div)
5 changes: 5 additions & 0 deletions ceil_mult.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Multiplication
from math import ceil
def multiplication(number_1, number_2):
mul = number_1 * number_2
return ceil(mul)
5 changes: 5 additions & 0 deletions ceil_sub.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Subtruction
from math import ceil
def subtruction(number_1, number_2):
sub = number_1 - number_2
return ceil(sub)