Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.92 KB | None | 0 0
  1. def getNumber(prompt):
  2.   while True:
  3.     text = input(prompt)
  4.  
  5.     if not text:
  6.       return None
  7.  
  8.     try:
  9.       number = float(text)
  10.       return number
  11.     except ValueError:
  12.       print("It's not a number\n")
  13.  
  14.  
  15. def getOperation():
  16.   while True:
  17.     operation = input("Enter the operation (Enter for exit): ")    
  18.  
  19.     if not operation:
  20.       return None
  21.  
  22.     if operation == '+':
  23.       return a + b
  24.    
  25.     if operation == '-':
  26.       return a - b
  27.  
  28.     if operation == '*':
  29.       return a * b
  30.  
  31.     if operation == '/':
  32.       return a / b
  33.  
  34.     else:
  35.       print("You've entered the incorrect operation\n")
  36.  
  37.  
  38. a = getNumber("Enter the first number (Enter for exit): ")
  39.  
  40. if a is not None:
  41.   b = getNumber("Enter the second number (Enter for exit): ")
  42.  
  43.   if b is not None:
  44.     result = getOperation()
  45.  
  46.     if result is not None:
  47.       print("\nYour result is: ", result)
  48.  
  49. print("\nSayonara!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement