SHARE
TWEET

Untitled

a guest May 31st, 2019 102 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. print("Simple python calculator (Task 2)")
  2. print("Choose what to do:")
  3. print("1-Add")
  4. print("2-Subtract")
  5. print("3-Multiply")
  6. print("4-Divide")
  7.  
  8. transaction = input("Enter transaction(1/2/3/4):") #asking user to choose transaction number
  9.  
  10. if transaction not in ('1', '2', '3', '4'): #if user's choice is not between transactions 1-4 print "invalid"
  11.     print("Invalid input")
  12.  
  13.  #else user's choice is between transactions 1-4 then ask num1 and num2
  14.  
  15. else:
  16.     num1 = int(input("Enter 1st number: "))
  17.     num2 = int(input("Enter 2nd number: "))
  18.  
  19. #here are the variables of calculation due to user's choice
  20.     getsum = num1 + num2
  21.     subtract = num1 - num2
  22.     multiply = num1 * num2
  23.     divide = num1 / num2
  24.  
  25.     if transaction == '1' or transaction == '+':
  26.         print(getsum)
  27.  
  28.     elif transaction == '2' or transaction == '-':
  29.         print(subtract)
  30.  
  31.     elif transaction == '3' or transaction == '*':
  32.         print(multiply)
  33.  
  34.     elif transaction == '4' or transaction == '/':
  35.         print(divide)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top