diff --git a/1.py b/1.py new file mode 100644 index 0000000..86c5c0e --- /dev/null +++ b/1.py @@ -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) \ No newline at end of file diff --git a/2.py b/2.py new file mode 100644 index 0000000..d3cbf98 --- /dev/null +++ b/2.py @@ -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") diff --git a/3.py b/3.py new file mode 100644 index 0000000..2d3fd0d --- /dev/null +++ b/3.py @@ -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.") \ No newline at end of file diff --git a/4.py b/4.py new file mode 100644 index 0000000..f82287b --- /dev/null +++ b/4.py @@ -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() \ No newline at end of file diff --git a/ceil_add.py b/ceil_add.py new file mode 100644 index 0000000..6d453f0 --- /dev/null +++ b/ceil_add.py @@ -0,0 +1,5 @@ +# Addition +from math import ceil +def addition(number_1, number_2): + sum = number_1 + number_2 + return ceil(sum) \ No newline at end of file diff --git a/ceil_div.py b/ceil_div.py new file mode 100644 index 0000000..03c6c3a --- /dev/null +++ b/ceil_div.py @@ -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) \ No newline at end of file diff --git a/ceil_mult.py b/ceil_mult.py new file mode 100644 index 0000000..86c0d74 --- /dev/null +++ b/ceil_mult.py @@ -0,0 +1,5 @@ +# Multiplication +from math import ceil +def multiplication(number_1, number_2): + mul = number_1 * number_2 + return ceil(mul) \ No newline at end of file diff --git a/ceil_sub.py b/ceil_sub.py new file mode 100644 index 0000000..d243dc3 --- /dev/null +++ b/ceil_sub.py @@ -0,0 +1,5 @@ +# Subtruction +from math import ceil +def subtruction(number_1, number_2): + sub = number_1 - number_2 + return ceil(sub) \ No newline at end of file