Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- finished = False
- while finished == False:
- #Greeting
- print("Hi, I am Marvin, your personal bot.")
- #Ask the user for a command
- command = input("How can I help? ")
- #Check for addition command
- if command == "add" or command == "plus" or command == "Add" or command == "Plus":
- print("let's add 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)
- #Check for subtraction command
- elif command == "subtract" or command == "take" or command == "Subtract" or command == "Take":
- 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)
- #Check for division command
- elif command == "divide" or command == "Divide":
- 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)
- #Check for multiply command
- elif command == "multiply" or command == "Multiply" or command == "times" or command == "Times":
- 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 + " x " + input2 + " = " + output)
- #Check for average command
- elif command == "average" or command == "Average":
- print("let's work out an average")
- how_many = input("How many numbers would you like to average?> ")
- how_many = int(how_many)
- total = 0
- number_list=[]
- for number_count in range(how_many):
- number = input("Enter number " + str(number_count+1) + "> ")
- total = total + int(number)
- number_list.append(number)
- result = total / how_many
- print("here are the numbers you wanted to average")
- for item in number_list:
- print(item)
- print("the average of those numbers = " +str(result))
- #Check for shopping list command
- elif command == "shopping" or command == "Shopping":
- #Create a shopping list calculator with given number of items based on user input and display it on screen
- shopping =[]
- how_many = input("how many items of shopping do you have? ")
- how_many_items = int(how_many)
- for item in range(how_many_items):
- new_item = input("Enter item number " + str(item+1) + " in the shopping list > ")
- shopping.append(new_item)
- #Print out the items
- for item in shopping:
- print(item)
- print("You added " + how_many + " items to the list")
- print("now let's calculate how much that will cost you!")
- total_cost=0
- for item in shopping:
- item_cost=input("how much is the item " + item + " in £ ? >")
- total_cost=total_cost+float(item_cost)
- print("the total cost of your shopping is £" + str(total_cost))
- elif command == "bye" or command == "Bye":
- finished = True
- #Error handling for unknown commands
- else:
- print("Sorry, I don't understand")
- print("Bye! Hope I was helpful!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement