diff --git a/Mis Calculator Q4/Addition.py b/Mis Calculator Q4/Addition.py new file mode 100644 index 0000000..f8456f3 --- /dev/null +++ b/Mis Calculator Q4/Addition.py @@ -0,0 +1,8 @@ +from math import ceil + +def add(a,b): + # This function returns the addition of two numbers + # The function rounds up the result if it is with decimals + return(ceil(float(a) + float(b))) + + \ No newline at end of file diff --git a/Mis Calculator Q4/Division.py b/Mis Calculator Q4/Division.py new file mode 100644 index 0000000..6af244f --- /dev/null +++ b/Mis Calculator Q4/Division.py @@ -0,0 +1,6 @@ +from math import ceil + +def divide(a,b): + # This function returns the division of two numbers + # The function rounds up the result if it is with decimals + return ceil(a / b) \ No newline at end of file diff --git a/Mis Calculator Q4/Mis_Calculator.py b/Mis Calculator Q4/Mis_Calculator.py new file mode 100644 index 0000000..d43b4c2 --- /dev/null +++ b/Mis Calculator Q4/Mis_Calculator.py @@ -0,0 +1,63 @@ +# Assignment week 4, question 1 + +from Addition import add +from Multiplication import Multiply +from Substraction import substract +from Division import divide + +def greetings_and_instructions(): + # Instructions to the user + print('Choose one of the following operations: ') + print('1- For Addition') + print('2- For Subtraction') + print('3- For Multiplication') + print('4- For Division') + + +print('Welcome to Mis Calculator') +greetings_and_instructions() + + +while True: + try: + user_choice = int(input('\nYour choice: ')) + assert user_choice > 0 and user_choice <= 4 + except ValueError: + print('You entered wrong choice, please choose again as displayed in the menu: ') + greetings_and_instructions() + continue + except AssertionError: + print('Your choice is not within the menu, please choose again as displayed in the menu: ') + greetings_and_instructions() + continue + + while True: + try: + a = float(input('Enter the first number: ')) + b = float(input('Enter the second number: ')) + except ValueError: + print('You did not enter a number, please enter a number:\n') + continue + else: + break + + + + if user_choice == 1: + print(a,'+',b ,'=',add(a,b)) + elif user_choice == 2: + print(a,'-',b ,'=',substract(a,b)) + elif user_choice == 3: + print(a,'*',b ,'=',Multiply(a,b)) + elif user_choice == 4: + print(a,'/',b ,'=',divide(a,b)) + + repeat = input('Do you want to repeat? (Yes), (Y) or (No) (N): ').upper() + + if repeat == 'Y' or repeat == 'YES': + greetings_and_instructions() + continue + if repeat != 'Y' or repeat != 'YES': + break + +print('Thank you! ') \ No newline at end of file diff --git a/Mis Calculator Q4/Multiplication.py b/Mis Calculator Q4/Multiplication.py new file mode 100644 index 0000000..59826bd --- /dev/null +++ b/Mis Calculator Q4/Multiplication.py @@ -0,0 +1,7 @@ +from math import ceil + +def Multiply(a,b): + # This function returns the mulitplication + # of two numbers + # The function rounds up the result if it is with decimals + return ceil(a * b) \ No newline at end of file diff --git a/Mis Calculator Q4/Substraction.py b/Mis Calculator Q4/Substraction.py new file mode 100644 index 0000000..b29c066 --- /dev/null +++ b/Mis Calculator Q4/Substraction.py @@ -0,0 +1,6 @@ +from math import ceil + +def substract(a,b): + # This function returns the substraction of two numbers + # The function rounds up the result if it is with decimals + return ceil(a - b) \ No newline at end of file diff --git a/Mis Calculator Q4/__pycache__/Addition.cpython-38.pyc b/Mis Calculator Q4/__pycache__/Addition.cpython-38.pyc new file mode 100644 index 0000000..ec0df9b Binary files /dev/null and b/Mis Calculator Q4/__pycache__/Addition.cpython-38.pyc differ diff --git a/Mis Calculator Q4/__pycache__/Division.cpython-38.pyc b/Mis Calculator Q4/__pycache__/Division.cpython-38.pyc new file mode 100644 index 0000000..fde82c6 Binary files /dev/null and b/Mis Calculator Q4/__pycache__/Division.cpython-38.pyc differ diff --git a/Mis Calculator Q4/__pycache__/Multiplication.cpython-38.pyc b/Mis Calculator Q4/__pycache__/Multiplication.cpython-38.pyc new file mode 100644 index 0000000..578a8c1 Binary files /dev/null and b/Mis Calculator Q4/__pycache__/Multiplication.cpython-38.pyc differ diff --git a/Mis Calculator Q4/__pycache__/Substraction.cpython-38.pyc b/Mis Calculator Q4/__pycache__/Substraction.cpython-38.pyc new file mode 100644 index 0000000..11cb8a5 Binary files /dev/null and b/Mis Calculator Q4/__pycache__/Substraction.cpython-38.pyc differ diff --git a/Q2 alphabet file/A.txt b/Q2 alphabet file/A.txt new file mode 100644 index 0000000..8c7e5a6 --- /dev/null +++ b/Q2 alphabet file/A.txt @@ -0,0 +1 @@ +A \ No newline at end of file diff --git a/Q2 alphabet file/B.txt b/Q2 alphabet file/B.txt new file mode 100644 index 0000000..7371f47 --- /dev/null +++ b/Q2 alphabet file/B.txt @@ -0,0 +1 @@ +B \ No newline at end of file diff --git a/Q2 alphabet file/C.txt b/Q2 alphabet file/C.txt new file mode 100644 index 0000000..96d80cd --- /dev/null +++ b/Q2 alphabet file/C.txt @@ -0,0 +1 @@ +C \ No newline at end of file diff --git a/Q2 alphabet file/D.txt b/Q2 alphabet file/D.txt new file mode 100644 index 0000000..02358d2 --- /dev/null +++ b/Q2 alphabet file/D.txt @@ -0,0 +1 @@ +D \ No newline at end of file diff --git a/Q2 alphabet file/E.txt b/Q2 alphabet file/E.txt new file mode 100644 index 0000000..9fb75b8 --- /dev/null +++ b/Q2 alphabet file/E.txt @@ -0,0 +1 @@ +E \ No newline at end of file diff --git a/Q2 alphabet file/F.txt b/Q2 alphabet file/F.txt new file mode 100644 index 0000000..c137216 --- /dev/null +++ b/Q2 alphabet file/F.txt @@ -0,0 +1 @@ +F \ No newline at end of file diff --git a/Q2 alphabet file/G.txt b/Q2 alphabet file/G.txt new file mode 100644 index 0000000..4fc3fe1 --- /dev/null +++ b/Q2 alphabet file/G.txt @@ -0,0 +1 @@ +G \ No newline at end of file diff --git a/Q2 alphabet file/H.txt b/Q2 alphabet file/H.txt new file mode 100644 index 0000000..8ac2eb5 --- /dev/null +++ b/Q2 alphabet file/H.txt @@ -0,0 +1 @@ +H \ No newline at end of file diff --git a/Q2 alphabet file/I.txt b/Q2 alphabet file/I.txt new file mode 100644 index 0000000..b4158c4 --- /dev/null +++ b/Q2 alphabet file/I.txt @@ -0,0 +1 @@ +I \ No newline at end of file diff --git a/Q2 alphabet file/J.txt b/Q2 alphabet file/J.txt new file mode 100644 index 0000000..22aac29 --- /dev/null +++ b/Q2 alphabet file/J.txt @@ -0,0 +1 @@ +J \ No newline at end of file diff --git a/Q2 alphabet file/K.txt b/Q2 alphabet file/K.txt new file mode 100644 index 0000000..449e49e --- /dev/null +++ b/Q2 alphabet file/K.txt @@ -0,0 +1 @@ +K \ No newline at end of file diff --git a/Q2 alphabet file/L.txt b/Q2 alphabet file/L.txt new file mode 100644 index 0000000..083b700 --- /dev/null +++ b/Q2 alphabet file/L.txt @@ -0,0 +1 @@ +L \ No newline at end of file diff --git a/Q2 alphabet file/M.txt b/Q2 alphabet file/M.txt new file mode 100644 index 0000000..ef6bce1 --- /dev/null +++ b/Q2 alphabet file/M.txt @@ -0,0 +1 @@ +M \ No newline at end of file diff --git a/Q2 alphabet file/N.txt b/Q2 alphabet file/N.txt new file mode 100644 index 0000000..2f94675 --- /dev/null +++ b/Q2 alphabet file/N.txt @@ -0,0 +1 @@ +N \ No newline at end of file diff --git a/Q2 alphabet file/O.txt b/Q2 alphabet file/O.txt new file mode 100644 index 0000000..60a89ed --- /dev/null +++ b/Q2 alphabet file/O.txt @@ -0,0 +1 @@ +O \ No newline at end of file diff --git a/Q2 alphabet file/P.txt b/Q2 alphabet file/P.txt new file mode 100644 index 0000000..675f43a --- /dev/null +++ b/Q2 alphabet file/P.txt @@ -0,0 +1 @@ +P \ No newline at end of file diff --git a/Q2 alphabet file/Q.txt b/Q2 alphabet file/Q.txt new file mode 100644 index 0000000..866ad47 --- /dev/null +++ b/Q2 alphabet file/Q.txt @@ -0,0 +1 @@ +Q \ No newline at end of file diff --git a/Q2 alphabet file/R.txt b/Q2 alphabet file/R.txt new file mode 100644 index 0000000..ac044e5 --- /dev/null +++ b/Q2 alphabet file/R.txt @@ -0,0 +1 @@ +R \ No newline at end of file diff --git a/Q2 alphabet file/S.txt b/Q2 alphabet file/S.txt new file mode 100644 index 0000000..1db515f --- /dev/null +++ b/Q2 alphabet file/S.txt @@ -0,0 +1 @@ +S \ No newline at end of file diff --git a/Q2 alphabet file/T.txt b/Q2 alphabet file/T.txt new file mode 100644 index 0000000..96583aa --- /dev/null +++ b/Q2 alphabet file/T.txt @@ -0,0 +1 @@ +T \ No newline at end of file diff --git a/Q2 alphabet file/U.txt b/Q2 alphabet file/U.txt new file mode 100644 index 0000000..4f0734c --- /dev/null +++ b/Q2 alphabet file/U.txt @@ -0,0 +1 @@ +U \ No newline at end of file diff --git a/Q2 alphabet file/V.txt b/Q2 alphabet file/V.txt new file mode 100644 index 0000000..d426ba8 --- /dev/null +++ b/Q2 alphabet file/V.txt @@ -0,0 +1 @@ +V \ No newline at end of file diff --git a/Q2 alphabet file/W.txt b/Q2 alphabet file/W.txt new file mode 100644 index 0000000..05fdf94 --- /dev/null +++ b/Q2 alphabet file/W.txt @@ -0,0 +1 @@ +W \ No newline at end of file diff --git a/Q2 alphabet file/X.txt b/Q2 alphabet file/X.txt new file mode 100644 index 0000000..500c070 --- /dev/null +++ b/Q2 alphabet file/X.txt @@ -0,0 +1 @@ +X \ No newline at end of file diff --git a/Q2 alphabet file/Y.txt b/Q2 alphabet file/Y.txt new file mode 100644 index 0000000..24de910 --- /dev/null +++ b/Q2 alphabet file/Y.txt @@ -0,0 +1 @@ +Y \ No newline at end of file diff --git a/Q2 alphabet file/Z.txt b/Q2 alphabet file/Z.txt new file mode 100644 index 0000000..0f13712 --- /dev/null +++ b/Q2 alphabet file/Z.txt @@ -0,0 +1 @@ +Z \ No newline at end of file diff --git a/q1.py b/q1.py new file mode 100644 index 0000000..3bf8bcb --- /dev/null +++ b/q1.py @@ -0,0 +1,30 @@ +# Assignment week 4, question 1 +import string + +capital_letters = string.ascii_uppercase +lwoer_case_letters = string.ascii_lowercase + + +def letters_with_specific_numbers(n): + """ + This function creates a file where all letters + of English alphabet(uppercase and lowercase both) + are listed by specified number of letters on each line. + """ + lst = [] + with open("q1.txt", "w") as f: + for i in range(0, len(capital_letters), n): + letter = capital_letters[i : i + n] + lst.append(letter) + + f.write("\n".join(lst)) + f.write("\n") + lst2 = [] + for i in range(0, len(lwoer_case_letters), n): + letter = lwoer_case_letters[i : i + n] + lst2.append(letter) + + f.write("\n".join(lst2)) + + +letters_with_specific_numbers(3) diff --git a/q1.txt b/q1.txt new file mode 100644 index 0000000..141a731 --- /dev/null +++ b/q1.txt @@ -0,0 +1,18 @@ +ABC +DEF +GHI +JKL +MNO +PQR +STU +VWX +YZ +abc +def +ghi +jkl +mno +pqr +stu +vwx +yz \ No newline at end of file diff --git a/q2.py b/q2.py new file mode 100644 index 0000000..3915287 --- /dev/null +++ b/q2.py @@ -0,0 +1,18 @@ +# Assignment week_4, question 2 +import string +import os + + +# store the text files in q2 alphabet directory +if os.path.exists("Q2 alphabet file"): + pass +else: + os.mkdir("Q2 alphabet file") + +# change the directory to \q2 alphabet file +os.chdir("Q2 alphabet file") +letters = string.ascii_uppercase + +for i in letters: + with open(i + ".txt", "w") as f: + f.write(i) diff --git a/q3.py b/q3.py new file mode 100644 index 0000000..c08cf05 --- /dev/null +++ b/q3.py @@ -0,0 +1,27 @@ +# Assignment week_4, question 3 +from math import gcd + + +def lcm(*input): + # This function returns the LCM value for 2 or more given inputs + lcmm = input[0] + for i in range(1,len(input)): + lcmm = lcmm * input[i]//gcd(lcmm, input[i]) + return lcmm + + +print("Welcome to LCM calculator: ") + +while True: + try: + user_input = [] + # take 4 inputs + for i in range(1, 5): + a = int(input("Enter input number " + str(i) + " : ")) + user_input.append(a) + except ValueError: + print("Invalid entry, please enter inegers") + continue + else: + print("The LCM for the entered inputs is:", lcm(*user_input)) + break \ No newline at end of file