Advertisement
zhongnaomi

def , add number or subtract

Jan 22nd, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.82 KB | None | 0 0
  1. def do_calculation():
  2.     print("lets " + command + " some numbers")
  3.     input1 = input("Number 1> ")
  4.     input2 = input("Number 2> ")
  5.     number1 = int(input1)
  6.     number2 = int(input2)
  7.     if command == "add"  :
  8.         result = number1 + number2
  9.         k = "+"
  10.     elif command == "subtract" :
  11.         result = number1 - number2
  12.         k ="-"            
  13.     output = str(result)
  14.     print(input1 + k + input2 + " = " + output)
  15.            
  16. finished = False
  17. while finished == False :
  18.     print("Hi, I am Marvin, your personal bot.")
  19.     command = input("How can I help? ")
  20.     if command == "add":
  21.         do_calculation()
  22.  
  23.     elif command == "subtract":
  24.         do_calculation()
  25.        
  26.     elif command == "bye" :
  27.         finished = True
  28.     else :
  29.         print ("Sorry I do not understand this " )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement