diff --git a/Add_calc.py b/Add_calc.py new file mode 100644 index 0000000..6da8022 --- /dev/null +++ b/Add_calc.py @@ -0,0 +1,8 @@ +#Addition + +from math import ceil + +def addition (n_1,n_2): + + sum= n_1+n_2 + return ceil(sum) \ No newline at end of file diff --git a/Answ_1.py b/Answ_1.py new file mode 100644 index 0000000..cbc353e --- /dev/null +++ b/Answ_1.py @@ -0,0 +1,13 @@ +## Letters for each line + +# Write a Python program to create a file where +# all letters of English alphabet(uppercase and lowercase both) +# are listed by specified number of letters on each line. + +import string + +with open('letters_file.txt', 'w') as f: + letters=string.ascii_letters + for i,letter in enumerate(letters,1): + f.write(f'{i} {letter}\n') #on every line write number and letter + diff --git a/Answ_2.py b/Answ_2.py new file mode 100644 index 0000000..7007e7f --- /dev/null +++ b/Answ_2.py @@ -0,0 +1,16 @@ +## Question 2 + +# Write a Python program to generate 26 text files named A.txt, B.txt, +# and so on up to Z.txt. + +import string +import os + +os.mkdir('Letters') #make a directory for alphabet files + +os.chdir('Letters') #make the 'Letters' a current directory + +letters=string.ascii_uppercase #make a sequence of uppercase letters. +for letter in letters: # loop to creat lettersnamed files + with open(f'{letter}.txt','x'): + pass \ No newline at end of file diff --git a/Answ_3.py b/Answ_3.py new file mode 100644 index 0000000..e3f81ae --- /dev/null +++ b/Answ_3.py @@ -0,0 +1,32 @@ +## LCM + +# As a user, I want to use a program which can calculate the least common +# multiple (L.C.M.) of four numbers. So that I can find the +# least common multiple (L.C.M.) of my inputs. + +# **Acceptance Criteria:** + +# * Ask user to enter the four numbers. +# * Use try/except blocks to verify input entries and warn the user +# for Nan or non numerical inputs. +# * Calculate the least common multiple (L.C.M.) of four numbers +# * Use gcd function in module of math + +import sys #import module sys to get a type of exception +from math import lcm #import lcm + + + +print('Enter 4 numbers.') +try: + a,b,c,d = list(map(int, input('Numbers - ').split())) #input numbers + # print(a,c,d) +except ValueError as e: #to verify input entries + print() + print('Plese enter integer numbers!') + print('Try again!') + # Calculate the least common multiple (L.C.M.) of four numbers + # use lcm (not gcd) function! +print('least common multiple (L.C.M.) of four numbers',lcm(a,b,c,d)) + + diff --git a/Answ_4.py b/Answ_4.py new file mode 100644 index 0000000..803956f --- /dev/null +++ b/Answ_4.py @@ -0,0 +1,62 @@ +## 4- Mis Calculator + +# As a user, I want to use a program which can calculate basic +# mathematical operations. So that I can add, subtract, +# multiply or divide my inputs. + +# **Acceptance Criteria:** + +# * The calculator must support the Addition, Subtraction, Multiplication +# and Division operations. +# * Define four functions in four files for each of them, with two float +# numbers as parameters. +# * To calculate the answer, use math.ceil()  and get the next integer +# value greater than the result +# * Create a menu using the print command with the respective options +# and take an input choice from the user. +# * Using if/elif statements for cases and call the appropriate functions. +# * Use try/except blocks to verify input entries and warn the user +# for incorrect inputs. +# * Ask user if calculate numbers again. To implement this, take the +# input from user `Y` or `N`. + +from Add_calc import * +from Divis_calc import * +from Mult_calc import * +from Substr_calc import * + +actions = { + '/': divis, + '+': addition, + '-': substract, + '*': multipl +} + +while True: + try: + print('\n\n Hello to Mis Calculator!\n') + a = float(input('Enter first number -')) + b = float(input('Enter second number -')) + + + action = input('''Chose the action. + Enter character: + + for add + - for subtract + * for multiply + / for divide''') + assert action in actions + print(f'The result is {(actions[action](a,b))}') + except ValueError as e: + print() + print('Enter number only!') + print() + except AssertionError: + print() + print('Unavailable action.') + + answer = input('Whould you like to continue? Y or N... ') + if answer.lower() in 'yes': + continue + else: + break diff --git a/Divis_calc.py b/Divis_calc.py new file mode 100644 index 0000000..7514e0b --- /dev/null +++ b/Divis_calc.py @@ -0,0 +1,10 @@ +#Division + +from math import ceil + +def divis (n_1,n_2): + try: + div= n_1/n_2 + except ZeroDivisionError: + print('Sorry, it is not possible!') + return ceil(div) \ No newline at end of file diff --git a/Mult_calc.py b/Mult_calc.py new file mode 100644 index 0000000..a182095 --- /dev/null +++ b/Mult_calc.py @@ -0,0 +1,8 @@ +#Multiplication + +from math import ceil + +def multipl (n_1,n_2): + + mult= n_1*n_2 + return ceil(mult) \ No newline at end of file diff --git a/Substr_calc.py b/Substr_calc.py new file mode 100644 index 0000000..06be0a7 --- /dev/null +++ b/Substr_calc.py @@ -0,0 +1,8 @@ +#Substraction + +from math import ceil + +def substract (n_1,n_2): + + sub = n_1-n_2 + return ceil(sub) \ No newline at end of file diff --git a/__pycache__/Add_calc.cpython-310.pyc b/__pycache__/Add_calc.cpython-310.pyc new file mode 100644 index 0000000..ef1a690 Binary files /dev/null and b/__pycache__/Add_calc.cpython-310.pyc differ diff --git a/__pycache__/Divis_calc.cpython-310.pyc b/__pycache__/Divis_calc.cpython-310.pyc new file mode 100644 index 0000000..22ec6a8 Binary files /dev/null and b/__pycache__/Divis_calc.cpython-310.pyc differ diff --git a/__pycache__/Mult_calc.cpython-310.pyc b/__pycache__/Mult_calc.cpython-310.pyc new file mode 100644 index 0000000..f213487 Binary files /dev/null and b/__pycache__/Mult_calc.cpython-310.pyc differ diff --git a/__pycache__/Substr_calc.cpython-310.pyc b/__pycache__/Substr_calc.cpython-310.pyc new file mode 100644 index 0000000..b9854c3 Binary files /dev/null and b/__pycache__/Substr_calc.cpython-310.pyc differ