Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- print("Hi, I am Marvin, your personal bot.")
- command = input("How can I help? ")
- if command == "add" or command == "plus" or command == "+":
- print("Let's add some numbers")
- input1 = input("Number 1> ") # These numbers are input as strings
- input2 = input("Number 2> ") # Python can't add strings
- number1 = int(input1) # convert input number to an integer
- number2 = int(input2) # Python *can* do arthmetic with integers
- result = number1 + number2
- output = str(result) # Integer has to be converted back to string
- print(input1 + " + " + input2 + " = " + output)
- elif command == "subtract" or command == "minus" or command == "-":
- print("Let's subtract some numbers")
- input1 = input("Number 1> ")
- input2 = input("Number 2> ")
- number1 = int(input1)
- number2 = int(input2)
- result = number1 - number2
- output = str(result)
- print(input1 + " - " + input2 + " = " + output)
- elif command == "multiply" or command == "times" or command == "*":
- print("Let's multiply some numbers")
- input1 = input("Number 1> ")
- input2 = input("Number 2> ")
- number1 = int(input1)
- number2 = int(input2)
- result = number1 * number2
- output = str(result)
- print(input1 + " * " + input2 + " = " + output)
- elif command == "divide" or command == "share" or command == "/":
- print("Let's divide some numbers")
- input1 = input("Number 1> ")
- input2 = input("Number 2> ")
- number1 = int(input1)
- number2 = int(input2)
- result = number1 / number2
- output = str(result)
- print(input1 + " / " + input2 + " = " + output)
- elif command == "average" or command == "mean":
- how_many = input("How many numbers? ")
- how_many = int(how_many)
- total = 0
- for number_count in range(how_many):
- number = input("Enter number " + str(number_count + 1) + "> ")
- total = total + int(number)
- result = total / how_many
- print("the average =",result)
- else:
- print("I'm sorry, I've not been programmed to " + command)
- print("Done")
Advertisement
Add Comment
Please, Sign In to add comment