Advertisement
Guest User

Untitled

a guest
Feb 21st, 2020
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.09 KB | None | 0 0
  1. #Greeting
  2. print("Hi, I am Marvin, your personal bot.")
  3.  
  4. #Ask the user for a command
  5. command = input("How can I help? ")
  6.  
  7. #Check for addition command
  8.  
  9. if command == "add" or command == "plus" or command == "Add" or command == "Plus":
  10.     print("let's add some numbers")
  11.     input1 = input("Number 1> ")
  12.     input2 = input("Number 2> ")
  13.     number1 = int(input1)
  14.     number2 = int(input2)
  15.     result = number1 + number2
  16.     output = str(result)
  17.     print(input1 + " + " + input2 + " = " + output)
  18.  
  19. #Check for subtraction command 
  20.  
  21. elif command == "subtract" or command == "take" or command == "Subtract" or command == "Take":
  22.     print("let's subtract 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.  
  31. #Check for division command
  32.  
  33. elif command == "divide" or command == "Divide":
  34.     print("let's divide some numbers")
  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.    
  43. #Check for multiply command
  44.  
  45. elif command == "multiply" or command == "Multiply" or command == "times" or command == "Times":
  46.     print("let's multiply some numbers")
  47.     input1 = input("Number 1> ")
  48.     input2 = input("Number 2> ")
  49.     number1 = int(input1)
  50.     number2 = int(input2)
  51.     result = number1 * number2
  52.     output = str(result)
  53.     print(input1 + " x " + input2 + " = " + output)
  54.  
  55.  
  56. #Check for average command
  57.  
  58. elif command == "average" or command == "Average":
  59.     print("let's work out an average")
  60.     how_many = input("How many numbers would you like to average?> ")
  61.     how_many = int(how_many)
  62.     total = 0
  63.     for number_count in range(how_many):
  64.         number = input("Enter number " + str(number_count+1) + "> ")
  65.         total = total + int(number)
  66.     result = total / how_many
  67.     print("the average = " +str(result))
  68.    
  69. #Error handling for unknown commands
  70.  
  71. else:
  72.     print("Sorry, I don't understand")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement