Advertisement
LHerr

elif add, subtract, multiply, divide

Feb 19th, 2020
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. print ("Hi, my name is Lisa, our personal bot.")
  2. command = input("How can I help? Would you like to add, subtract, multiply, or divide?")
  3. #asking user to input whether to add or subtract
  4. if command == "add" or command == "plus":
  5. #use the or if there are varying correct answers
  6. print ("Wonderful. I will need the numbers you would like to add.")
  7. input1 = input("Number 1>")
  8. input2 = input("Number 2>")
  9. number1 = int(input1)
  10. #used to change a string to an integer for calculations
  11. number2 = int(input2)
  12. result = number1 + number2
  13. output = str(result)
  14. print (input1 + "+" + input2 + "=" + output)
  15. elif command == "subtract" or command == "minus":
  16. print ("Wonderful. I will need the numbers you would like to subtract")
  17. input1 = input("Number 1>")
  18. input2 = input("Number 2>")
  19. number1 = int(input1)
  20. number2 = int(input2)
  21. result = number1 - number2
  22. output = str(result)
  23. print (input1 + "-" + input2 + "=" + output)
  24. elif command == "multiply" or command == "times":
  25. print ("Wonderful. I will need the numbers you would like to multiply")
  26. input1 = input("Number 1>")
  27. input2 = input("Number 2>")
  28. number1 = int(input1)
  29. number2 = int(input2)
  30. result = number1 * number2
  31. output = str(result)
  32. print (input1 + "x" + input2 + "=" + output)
  33. elif command == "divide":
  34. print ("Wonderful. I will need the numbers you would like to divide")
  35. input1 = input("Number 1>")
  36. input2 = input("Number 2>")
  37. number1 = int(input1)
  38. number2 = int(input2)
  39. result = number1 / number2
  40. output = str(result)
  41. print (input1 + "/" + input2 + "=" + output)
  42. else:
  43. print ("I am sorry I did not understand")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement