erynur

calc.py

Feb 10th, 2018
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.25 KB | None | 0 0
  1. #! coding='utf-8'
  2.  
  3. def add(a, b):
  4.     return a+b
  5.  
  6. def sub(a, b):
  7.     return a-b
  8.  
  9. def mul(a, b):
  10.     return a*b
  11.  
  12. def div(a, b):
  13.     return a/b
  14.  
  15. def mod(a, b):
  16.     return a%b
  17.  
  18. def n_root(n, r):
  19.     return r**(1/n)
  20.  
  21. def sin(a):
  22.     return sin(a)
  23.  
  24. def cos(a):
  25.     return cos(a)
  26.  
  27. def tan(a):
  28.     return tan(a)
  29.  
  30. options = {1:add, 2:sub, 3:mul, 4:div, 5:mod, 6:n_root, 7:sin, 8:cos, 9:tan}
  31.  
  32. print('Please choose your method: \n')
  33. print('(1) Addition (2) Subtraction (3) Multiplication (4) Divison')
  34. print('(5) Modulo (6) n-root (7) Sinus (8) Cosine (9) Tangent')
  35. choosen = int(input(': '))
  36. if choosen in options:
  37.     print('\nPlease enter the 2 numbers you want to operate with:')
  38.     print('Please use . (dot) not , (comma) for float.\n')
  39.     if choosen==6:
  40.         print('HINT: For n-root, first number is <n> and second number is <base>')
  41.         print('Example 1: first number: 2, second number: 10 is squareroot of 10')
  42.         print('Example 2: first number: 3, second number: 10 is third root of 10 \n')
  43.     first_number=float(input('First number: '))
  44.     second_number=float(input('Second number: '))
  45.     solution=options[choosen](first_number, second_number)
  46.     print(solution)
  47. else:
  48.     print('Please choose a operation from 1 to 9')
Advertisement
Add Comment
Please, Sign In to add comment