timpin

bot with mean

Aug 14th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. print("Hi, I am Marvin, your personal bot.")
  2. command = input("How can I help? ")
  3. if command == "add" or command == "plus" or command == "+":
  4. print("Let's add some numbers")
  5. input1 = input("Number 1> ") # These numbers are input as strings
  6. input2 = input("Number 2> ") # Python can't add strings
  7. number1 = int(input1) # convert input number to an integer
  8. number2 = int(input2) # Python *can* do arthmetic with integers
  9. result = number1 + number2
  10. output = str(result) # Integer has to be converted back to string
  11. print(input1 + " + " + input2 + " = " + output)
  12. elif command == "subtract" or command == "minus" or command == "-":
  13. print("Let's subtract some numbers")
  14. input1 = input("Number 1> ")
  15. input2 = input("Number 2> ")
  16. number1 = int(input1)
  17. number2 = int(input2)
  18. result = number1 - number2
  19. output = str(result)
  20. print(input1 + " - " + input2 + " = " + output)
  21. elif command == "multiply" or command == "times" or command == "*":
  22. print("Let's multiply some numbers")
  23. input1 = input("Number 1> ")
  24. input2 = input("Number 2> ")
  25. number1 = int(input1)
  26. number2 = int(input2)
  27. result = number1 * number2
  28. output = str(result)
  29. print(input1 + " * " + input2 + " = " + output)
  30. elif command == "divide" or command == "share" or command == "/":
  31. print("Let's divide some numbers")
  32. input1 = input("Number 1> ")
  33. input2 = input("Number 2> ")
  34. number1 = int(input1)
  35. number2 = int(input2)
  36. result = number1 / number2
  37. output = str(result)
  38. print(input1 + " / " + input2 + " = " + output)
  39. elif command == "average" or command == "mean":
  40. how_many = input("How many numbers? ")
  41. how_many = int(how_many)
  42. total = 0
  43. for number_count in range(how_many):
  44. number = input("Enter number " + str(number_count + 1) + "> ")
  45. total = total + int(number)
  46. result = total / how_many
  47. print("the average =",result)
  48.  
  49. else:
  50. print("I'm sorry, I've not been programmed to " + command)
  51. print("Done")
Advertisement
Add Comment
Please, Sign In to add comment