Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Futurelearn: Python 101 from RPi Foundation - Bot with functions
- def totalaverage():
- how_many = input("How many numbers do you have> ")
- 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)
- if command == "average":
- result = total / how_many
- else:
- result = total
- output = str(result)
- print("The " + command + " of your numbers = " + output)
- def do_calculation():
- print("lets " + command + " some numbers")
- input_1 = input("Number 1> ")
- input_2 = input("Number 2> ")
- number_1 = int(input_1)
- number_2 = int(input_2)
- if command == "add" or command == "plus":
- result = number_1 + number_2
- operator = " + "
- elif command == "subtract" or command == "take away":
- result = number_1 - number_2
- operator = " - "
- elif command == "multiply" or command == "times":
- result = number_1 * number_2
- operator = " * "
- elif command == "divide":
- result = number_1 / number_2
- operator = " / "
- output = str(result)
- print(str(input_1) + operator + str(input_2) + " = " + output)
- finished = False
- while finished == False:
- print("\nHi, I am your personal 'bot' called Dave.")
- command = input("How can I help you? ")
- if command == "add" or command == "plus":
- do_calculation()
- elif command == "subtract" or command == "take away":
- do_calculation()
- elif command == "multiply" or command == "times":
- do_calculation()
- elif command == "divide":
- do_calculation()
- elif command == "average" or command == "total":
- totalaverage()
- elif command == "meal":
- people = int(input("how many people ate a meal> "))
- total = 0
- for meal in range(people):
- cost = float(input("How much was meal " + str(meal+1) + "? "))
- total = total + cost
- print("Each person will need to pay " + str(round(total/people,2)) + " pounds\dollars each.")
- elif command == "bye":
- finished = True
- else:
- print("Sorry I don't understand")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement