Advertisement
HBSB

2.15 Challenge +-*/

Jan 11th, 2020
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.46 KB | None | 0 0
  1. # I want this program to help with simple calculations
  2. print ("Hi, I am Marvin, your personal bot")
  3. command = input ("How can I help?  I can add, subtract, multiply or divide.  You choose.")
  4. # The user can choose between the options Marvin gives
  5.  
  6.  
  7.  
  8. if command == "add":
  9.  
  10.  
  11.   input1 = input("Number 1> ")
  12.   input2 = input("Number 2> ")
  13.  
  14.   number1 = float(input1)
  15.   number2 = float(input2)
  16.  
  17.   result = number1 + number2
  18.   output = str(result)
  19.   print(input1 + " + " + input2 + " = " + output)
  20.  
  21. # the next option is subtraction
  22. elif command == "subtract":
  23.   input1 = input("number1>")
  24.   input2 = input("number2>")
  25.   number1 = float(input1)
  26.   number2 = float(input2)
  27.   result = number1 - number2
  28.   output = str(result)
  29.   print(input1 + " - " + input2 + " = " + output)
  30.  
  31. # the next option is multiplication
  32. elif command == "multiply":
  33.   input1 = input("number1>")
  34.   input2 = input("number2>")
  35.   number1 = float(input1)
  36.   number2 = float(input2)
  37.   result = number1 * number2
  38.   output = str(result)
  39.   print(input1 + "*" + input2 + "=" + output)
  40.  
  41. # the next option is dividing the height and width of a structure
  42. elif command == "divide":
  43.  
  44.   input1 = input("number1>")
  45.   input2 = input("number2>")
  46.   number1 = float(input1)
  47.   number2 = float(input2)
  48.   result = number1/number2
  49.   output = str(result)
  50.   print(input1 + "/" + input2 + "=" + output)
  51.  
  52. # or if the user input doesn't match then tell them
  53. else:
  54.   print("I don't understand")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement