def main(): x = int( input( 'enter 1 if you want to use exp_root \n enter 2 if you want to use factorial \n enter 3 if you want to use logarithm: ' )) if x == 1: y = int( input( 'enter 1 if you want to use exponentiation \n enter 2 if you want to use root: ' )) if y == 1: z = int( input( 'enter 1 if you want to use exp2 \n enter 2 if you want to use exp3: ' )) if z == 1: exponentiation.exp2(float(input('Введіть число: '))) elif z == 2: exponentiation.exp3(float(input('Введіть число: '))) elif y == 2: l = int( input( 'enter 1 if you want to use root2 \n enter 2 if you want to use root3: ' )) if l == 1: root.root2(float(input('Введіть число: '))) elif l == 2: root.root3(float(input('Введіть число: '))) elif x == 2: factorial.fact(float(input('Введіть число: '))) elif x == 3: m = int( input( 'enter 1 if you want to use log \n enter 2 if you want to use ln \n enter 3 if you want to use lg: ' )) if m == 1: logarithm.log(float(input('Введіть основу: ')), float(input('Введіть число: '))) elif m == 2: logarithm.ln(float(input('Введіть число: '))) elif m == 3: logarithm.lg(float(input('Введіть число: '))) while True: res = input('Запустити програму заново? ') if res == 'Так': main() else: sys.exit(0)
def main(ch): """ This function is print result for the selected function """ try: # Here is the search and launch of the selected function if ch == '1': result = fact(int(input("Factorial for "))) if ch == '2': result = exp2(float(input("Square exponention for "))) if ch == '3': result = exp3(float(input("Cube exponention for "))) if ch == '4': result = root2(float(input("Square root for "))) if ch == '5': result = root3(float(input("Cube root for "))) if ch == '6': a = float(input("Enter a base for this logarithm: ")) b = float(input("Enter b in this logarithm: ")) result = log(a, b) if ch == '7': b = float(input("Enter b in this logarithm: ")) result = lg(b) if ch == '8': b = float(input("Enter b in this logarithm: ")) result = ln(b) # Here is output result print("Result:", result) except ArithmeticError: print("Incorrect a values")
def testFactorial3(): assert factorial.fact(6) == 3
def testFactorial2(): assert factorial.fact(40320) == 8
def testFactorial1(): assert factorial.fact(3628800) == 10
def testFactorial5(): assert factorial.fact(720) == 6
def testFactorialLarge(): assert factorial.fact(479001600) == 12
def testFactorialNone(): assert factorial.fact(18) == "NONE"
from exp_root.root import * from exp_root.exponentiation import * choice = input( 'Write 1 to use the factorial module, 2 - to use the logarithm module and 3 to use exp_root module' ) list = ['1', '2', '3'] while choice not in list: choice = input('Please check your data.') if choice == '1': a = input('Enter an int. number please: ') while a.isdigit() != True: a = input('Please check your data.') print('The answer is ', fact(int(a))) if choice == '2': choice_0 = input( 'Enter 1 to use log() function, 2 - to use ln() function and 3 for lg()' ) while choice_0 not in list: choice_0 = input('Please check your data.') if choice_0 == '1': choice_0_a = input('Enter the 1st numb') choice_0_b = input('Enter the 2nd numb') try: choice_0_a = float(choice_0_a) while float(choice_0_a) < 0: choice_0_a = input('Please check your data.')
from factorial.factorial import fact from logarithm.logarithm import * from exp_root.root import * from exp_root.exponentiation import * vybor = input('Which module do you want to use?(1-factorial\ 2-exp_root\smth else-logarithm)') if vybor=='1': while True: n = input('Enter n for factorial calculation: ') try: n = int(n) if n < 0: raise Exception print('factorial:'+str(fact(n))) break except Exception: print('Uncorrect data!') break elif vybor=='2': while True: n = input('Which module do you want to use?(1-root\ 2-exponentation) ') try: if n!='1' and n!='2': raise Exception if n == '1': while True: n1 = input('Enter n for root calculation: ') try: n1 = int(n1) if n1 < 0: raise Exception print('root2:' + str(root2(n1)))
def main(): print() print("Please, choose which function do you want to test.\n" "Type fact or exp2 or exp3 or root2 or root3 or ln or log or lg.") selected = input() if selected == "fact": n = input("Type number n: ") try: n = int(n) if n < 0: return "You entered not a natural number" else: return fact(n) except ValueError: return "You entered not a number." elif selected == "exp2": n = input("Type number n: ") try: n = float(n) return exp2(n) except ValueError: return "You entered not a number." elif selected == "exp3": n = input("Type number n: ") try: n = float(n) return exp3(n) except ValueError: return "You entered not a number." elif selected == "root2": n = input("Type number n: ") try: n = float(n) if n < 0: return "You entered not a positive number" else: return root2(n) except ValueError: return "You entered not a number." elif selected == "root3": n = input("Type number n: ") try: n = float(n) return root3(n) except ValueError: return "You entered not a number." elif selected == "log": a = input("Type base a: ") b = input("Type number b: ") try: a = float(a) b = float(b) if (b > 0) and (a > 0) and (a != 1): return log(b, a) else: return "a and b must be positive and a != 1." except ValueError: return "1 or more of your inputs are not a number." elif selected == "lg": b = input("Type number b: ") try: b = float(b) if b > 0: return lg(b) else: return "b must be positive." except ValueError: return "You entered not a number." elif selected == "ln": b = input("Type number b: ") try: b = float(b) if b > 0: return ln(b) else: return "b must be positive." except ValueError: return "You entered not a number." else: print("This function is not planned for testing :(")
from factorial import factorial factorial.fact(5)
def main(): while True: print("--------------------------") print( 'Choose the operation you want to do. Input:\n' '"1" for factorial;\n' '"2.1" for square of number, "2.2" for cube of number;\n' '"3.1" for square root, "3.2" for cube root;\n' '"4.1" for ln of number, "4.2" for lg of number, "4.3" for log of number with your base;\n' 'anything else to stop the program.') ans = input("Your choice:") if ans == "1": n = int_check(input("Enter your number(must be natural):")) while True: if n <= 0: print( "Error: your number is not natural. Choose another number." ) n = int_check(input("Enter your number(must be natural):")) else: break print("Your factorial is:", factorial.fact(n)) elif ans == "2.1": n = float_check(input("Enter your number:")) print("Square of your number is:", exponentiation.exp2(n)) elif ans == "2.2": n = float_check(input("Enter your number:")) print("Cube of your number is:", exponentiation.exp3(n)) elif ans == "3.1": n = float_check(input("Enter your number(must be non-negative):")) while True: if n < 0: print( "Can`t find square root of your number. Please, choose another number." ) n = float_check( input("Enter your number(must be non-negative):")) else: break print("Square root of your number is:", root.root2(n)) elif ans == "3.2": n = float_check(input("Enter your number:")) print("Cube root of your number is:", root.root3(n)) elif ans == "4.1": n = float_check(input("Enter your number(must be non-negative):")) while True: if n <= 0: print( "Can`t find ln of your number. Please, choose another number." ) n = float_check( input("Enter your number(must be non-negative):")) else: break print("ln of your number is:", logarithm.ln(n)) elif ans == "4.2": n = float_check(input("Enter your number(must be non-negative):")) while True: if n <= 0: print( "Can`t find ln of your number. Please, choose another number." ) n = float_check( input("Enter your number(must be non-negative):")) else: break print("lg of your number is:", logarithm.lg(n)) elif ans == "4.3": a = float_check( input( "Enter your base(must be non-negative and not equals to 1):" )) while True: if a < 0 or a == 1: print( "Can`t be base of logarithm. Please, choose another number." ) a = float_check( input("Enter your number(must be non-negative):")) else: break b = float_check(input("Enter your number(must be non-negative):")) while True: if b <= 0: print( "Can`t be base of logarithm. Please, choose another number." ) a = float_check( input("Enter your number(must be non-negative):")) else: break print("log of your number with your base is:", logarithm.log(a, b)) else: print( "Wrong input, so work is stopped. Thank you for using this program!" ) break
def main(): print("MENU:") print("- enter 1 if you want to find factorial") print("- enter 2 if you want to find exponentiation(2 degree)") print("- enter 3 if you want to find exponentiation(3 degree)") print("- enter 4 if you want to find root(2 degree)") print("- enter 5 if you want to find root(3 degree)") print("- enter 6 if you want to find log") print("- enter 7 if you want to find ln") print("- enter 8 if you want to find lg") print() while True: variant = input() if variant == "1": print("enter the integer, which >= 0") while True: a = input() try: a = int(a) if a < 0: print("invalid number") continue else: result = factorial.fact(a) print() print("result:", result) return result except ValueError: print("invalid number") elif variant == "2": print("enter the number") while True: a = input() try: a = float(a) result = exponentiation.exp2(a) print() print("result:", result) return result except ValueError: print("invalid number") elif variant == "3": print("enter the number") while True: a = input() try: a = float(a) result = exponentiation.exp3(a) print() print("result:", result) return result except ValueError: print("invalid number") elif variant == "4": print("enter the number >= 0") while True: a = input() try: a = float(a) if a < 0: print("invalid number") continue else: result = root.root2(a) print() print("result:", result) return result except ValueError: print("invalid number") elif variant == "5": print("enter the number") while True: a = input() try: a = float(a) result = root.root3(a) print() print("result:", result) return result except ValueError: print("invalid number") elif variant == "6": print("enter the base") while True: a = input() try: a = float(a) if a <= 0: print("incorrect base") elif a == 1: print("incorrect base") else: break except ValueError: print("incorrect base") print("enter the number") while True: b = input() try: b = float(b) if b <= 0: print("incorrect number") else: result = logarithm.log(a, b) print() print("result:", result) return result except ValueError: print("incorrect number") elif variant == "7": print("enter the number") while True: a = input() try: a = float(a) if a <= 0: print("incorrect number") else: result = logarithm.ln(a) print() print("result:", result) return result except ValueError: print("incorrect number") elif variant == "8": print("enter the number") while True: a = input() try: a = float(a) if a <= 0: print("incorrect number") else: result = logarithm.lg(a) print() print("result:", result) return result except ValueError: print("incorrect number") else: print("incorrect")
"Please choose one of the following functions: factorial(1), exp_root(2) or logarithm(3)" ) while True: try: user_input = int(input("Enter number 1, 2 or 3: ")) break except ValueError: continue if user_input == 1: while True: try: n = int(input("Enter natural number: ")) if n < 0: continue print("Factorial is", factorial.fact(n)) break except ValueError: continue elif user_input == 2: print( "Choose if you want to raise a number to a power(1) or find number's root(2)" ) while True: try: user_input2 = int(input("Enter number 1 or 2: ")) break except ValueError: continue if user_input2 == 1: print(
def testFactorial4(): assert factorial.fact(24) == 4
def _main(): print('-' * 20) print( "Якщо ви хочете знайти факторіал - введіть factorial\nЯкщо корінь квадратний - введіть root2\nЯкщо кубічний - введіть root3\nЯкщо логарифм з певною основою - log\nЯкщо натуральний логарифм - введіть ln\nЯкщо логарифм з основою 10 - lg\nЯкщо квадрат - введіть exp2\nЯкщо куб числа - введіть exp3" ) print('-' * 20) print("Якщо хочете завершити програму - введіть break") print('-' * 20) while True: while True: print('-' * 20) a = input("Що ви хочете обчислити?") if a == "break" or a == "BREAK": print("До побачення!!!!!!!!") break else: if a != 'factorial' and a != 'root2' and a != 'root3' and a != 'log' and a != 'ln' and a != 'lg' and a != 'exp2' and a != 'exp3': print("Введені невірні дані.") raise ValueError if a == "factorial": b = int( input( "Введіть число для якого потрібно знайти факторіал: " )) if b < 0: print("Введіть додатне число") raise ValueError else: print("Відповідь: ", factorial.fact(b)) elif a == "root2": b = float( input( "Введіть число для якого хочете знайти корінь: ")) if b < 0: print("Введіть додатне число") raise ValueError else: print("Відповідь: ", root.root2(b)) elif a == 'root3': b = float( input( "Введіть число для якого хочете знайти корінь: ")) print("Відповідь: ", root.root3(b)) elif a == 'log': b1 = float( input("Введіть число для знаходження логарифма: ")) if b1 < 0: print("Введіть додатне число") raise ValueError b2 = float(input("Введіть основу для логарифма: ")) if b2 < 0 or b2 == 1: print("Введіть додатне число") raise ValueError else: print("Відповідь: ", logarithm.log(b2, b1)) elif a == 'ln': b1 = float( input( "Введіть число для якого хочете знайти логарифм: ") ) if b1 < 0: raise ValueError else: print("Відповідь: ", logarithm.ln(b1)) elif a == 'lg': b1 = float( input( "Введіть число для якого хочете знайти логарифм: ") ) if b1 < 0: print("Введіть додатне число") raise ValueError else: print("Відповідь: ", logarithm.lg(b1)) elif a == 'exp2': b = float( input( "Введіть число для якого хочете знайти квадрат: ")) print("Відповідь: ", exponentiation.exp2(b)) elif a == 'exp3': b = float( input("Введіть число для якого хочете знайти куб: ")) print("Відповідь: ", exponentiation.exp3(b))
from factorial.factorial import fact from exp_root.exponentiation import exp2, exp3 from exp_root.root import root2, root3 from logarithm.logarithm import log, lg, ln try: if __name__ == '__main__': f = input( "Виберіть з нище вказаних функцій, ту що бажаєте використати\nФакторіал - f\nПіднесення до квадрату - 2, до кубу - 3\nЗнаходження корення квадратного - r2, кібучного - r3\nЛогарифма вибраного степеню - log, натурального - ln, десяткового - lg\n" ) if f == 'f': print( fact( input( "Введіть ціле додатнє число, від якого бажаєте знайти факторіал\t" ))) elif f == '2': print(exp2(input("Введіть число, квадрат якого бажаєте знайти\t"))) elif f == '3': print(exp3(input("Введіть число, куб якого бажаєте знайти\t"))) elif f == 'r2': print( root2( input( "Введіть число, корінь 2-го степеня якого бажаєте знайти\t" ))) elif f == 'r3': print( root3( input( "Введіть число, корінь 3-го степеня якого бажаєте знайти\t" )))