Advertisement
HBSB

2.15 + - / * and area

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