From aef183686065b2238e7fbd6def927b8b853ff036 Mon Sep 17 00:00:00 2001 From: abdullahalzaghir <121679105+abdullahalzaghir@users.noreply.github.com> Date: Mon, 6 Feb 2023 16:23:41 +0100 Subject: [PATCH 1/2] assignment week 4 submission --- Mis Calculator Q4/Addition.py | 8 +++ Mis Calculator Q4/Division.py | 6 ++ Mis Calculator Q4/Mis_Calculator.py | 63 ++++++++++++++++++ Mis Calculator Q4/Multiplication.py | 7 ++ Mis Calculator Q4/Substraction.py | 6 ++ .../__pycache__/Addition.cpython-38.pyc | Bin 0 -> 355 bytes .../__pycache__/Division.cpython-38.pyc | Bin 0 -> 341 bytes .../__pycache__/Multiplication.cpython-38.pyc | Bin 0 -> 349 bytes .../__pycache__/Substraction.cpython-38.pyc | Bin 0 -> 348 bytes Q2 alphabet file/A.txt | 1 + Q2 alphabet file/B.txt | 1 + Q2 alphabet file/C.txt | 1 + Q2 alphabet file/D.txt | 1 + Q2 alphabet file/E.txt | 1 + Q2 alphabet file/F.txt | 1 + Q2 alphabet file/G.txt | 1 + Q2 alphabet file/H.txt | 1 + Q2 alphabet file/I.txt | 1 + Q2 alphabet file/J.txt | 1 + Q2 alphabet file/K.txt | 1 + Q2 alphabet file/L.txt | 1 + Q2 alphabet file/M.txt | 1 + Q2 alphabet file/N.txt | 1 + Q2 alphabet file/O.txt | 1 + Q2 alphabet file/P.txt | 1 + Q2 alphabet file/Q.txt | 1 + Q2 alphabet file/R.txt | 1 + Q2 alphabet file/S.txt | 1 + Q2 alphabet file/T.txt | 1 + Q2 alphabet file/U.txt | 1 + Q2 alphabet file/V.txt | 1 + Q2 alphabet file/W.txt | 1 + Q2 alphabet file/X.txt | 1 + Q2 alphabet file/Y.txt | 1 + Q2 alphabet file/Z.txt | 1 + q1.py | 30 +++++++++ q1.txt | 18 +++++ q2.py | 18 +++++ q3.py | 27 ++++++++ 39 files changed, 209 insertions(+) create mode 100644 Mis Calculator Q4/Addition.py create mode 100644 Mis Calculator Q4/Division.py create mode 100644 Mis Calculator Q4/Mis_Calculator.py create mode 100644 Mis Calculator Q4/Multiplication.py create mode 100644 Mis Calculator Q4/Substraction.py create mode 100644 Mis Calculator Q4/__pycache__/Addition.cpython-38.pyc create mode 100644 Mis Calculator Q4/__pycache__/Division.cpython-38.pyc create mode 100644 Mis Calculator Q4/__pycache__/Multiplication.cpython-38.pyc create mode 100644 Mis Calculator Q4/__pycache__/Substraction.cpython-38.pyc create mode 100644 Q2 alphabet file/A.txt create mode 100644 Q2 alphabet file/B.txt create mode 100644 Q2 alphabet file/C.txt create mode 100644 Q2 alphabet file/D.txt create mode 100644 Q2 alphabet file/E.txt create mode 100644 Q2 alphabet file/F.txt create mode 100644 Q2 alphabet file/G.txt create mode 100644 Q2 alphabet file/H.txt create mode 100644 Q2 alphabet file/I.txt create mode 100644 Q2 alphabet file/J.txt create mode 100644 Q2 alphabet file/K.txt create mode 100644 Q2 alphabet file/L.txt create mode 100644 Q2 alphabet file/M.txt create mode 100644 Q2 alphabet file/N.txt create mode 100644 Q2 alphabet file/O.txt create mode 100644 Q2 alphabet file/P.txt create mode 100644 Q2 alphabet file/Q.txt create mode 100644 Q2 alphabet file/R.txt create mode 100644 Q2 alphabet file/S.txt create mode 100644 Q2 alphabet file/T.txt create mode 100644 Q2 alphabet file/U.txt create mode 100644 Q2 alphabet file/V.txt create mode 100644 Q2 alphabet file/W.txt create mode 100644 Q2 alphabet file/X.txt create mode 100644 Q2 alphabet file/Y.txt create mode 100644 Q2 alphabet file/Z.txt create mode 100644 q1.py create mode 100644 q1.txt create mode 100644 q2.py create mode 100644 q3.py 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 0000000000000000000000000000000000000000..ec0df9b9afb1416175e6c47650ea04f9489edfec GIT binary patch literal 355 zcmYjMO-sZu5Y41rUBtbKdfaOd@w5jK5tsV09$XPwgpx~|L^qhWOOt|vxB6%NJ05!z zPyPi@P6`YA;Jv(=Ooo@mXtYBR?f$p?!t*B-o1j>nBi$j2A_^=iAOj$Zs_27cRK*V@ z8T{fcNuZ0RHdcm5YXl!7Q>5EN@x;SBX#o{lI6#LBV4l!AjCO-3TM3`g4nzm}C#kov z`)A|{UpQSmKFw8QtyuDlN;ZWqz2n!$&zhX4RycRe9<_d%uq$IVyJ2_i@>S}UH&w}I zqEyzD&-~W7aVo5AtngJmzMt@^QYOqCt=_swC>4dU{V$?=h<=_#SzHLe>@)VQKG%k9 Rhw#JGqQZFk4Au*F=|3}GPRsxR literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..fde82c6dfc89cb1b73651c1f2b2ac0fe8216c10d GIT binary patch literal 341 zcmYjL!Ab)$5Y6nawMcsv!Aq}uh^HPzM3h#o2P+~)D7j>lV1wD+l4M1pH~pDjJ^CrR zi6?)-laqx)2i}``c{Ab7`u#nE^|}8ozOes9v0Vv@bA&rUl0tWa zg=~!B3pTDrQ>w~4cCG!SDcHzx=Z@*4QqMzrrH!ID^p0M>3bpjQuIPkU(&*}m-D)=& zaU&YTeQgK#LpIhg+TqU8@-1{E3aMg5*XB-b7w2i7hOFd%VWZPNwb8a{7md(8Eo)4u K&S3LFFZlXvJCBJZ%;}{U0qtRNLiGObY!Zi+xfuH#foQMqR|6asY-; PFUlH{%1gZcpcnlC^4(9t literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..11cb8a5c4323b48cc7ba7cadedbd5012acb48bf6 GIT binary patch literal 348 zcmYjLO-lnY5KXeHR%x%&W3PLNryfK^l=Y(?tVk(B$t9Zv8_e#OBnt|?)j!jJp?@Pc z@#J6d(&`FL-~V*aZP`33Nj!5=m@Oi5D0nNo4YY7DT2q zlKPFcsU z3fUOLm+ZP0O{psH*q!#1reL|@&YjX{rC!JMRvSg{=_9>)6KdskUC{}zq|wz2d(du_ zb0ZqVeQifiV>W9F=Peg;?_~8J4qZ2hNnIO1u|4RgSrXEc`=yOeJ8Bc|lmjqA@4T!b LsJg)22YvDnm}XCK literal 0 HcmV?d00001 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..5d41f45 --- /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 + 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 From 2a8171fc6a3b07ea495476f3b3fe024ffdf849cf Mon Sep 17 00:00:00 2001 From: abdullahalzaghir <121679105+abdullahalzaghir@users.noreply.github.com> Date: Mon, 6 Feb 2023 16:25:25 +0100 Subject: [PATCH 2/2] Update q3.py --- q3.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/q3.py b/q3.py index 5d41f45..c08cf05 100644 --- a/q3.py +++ b/q3.py @@ -15,7 +15,7 @@ def lcm(*input): while True: try: user_input = [] - # take 4 + # take 4 inputs for i in range(1, 5): a = int(input("Enter input number " + str(i) + " : ")) user_input.append(a)