Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Bot to answer user questions doing basic maths
- deviceName = "Bot"
- print("Hello, I am your personal " + deviceName)
- users_name = input("What is your your name? ")
- print("Hello " + users_name +", it good to meet you.")
- print("I can do calculation for you to add, subtract, divide, multiple and average values")
- print("Choose your operation from the list below")
- command = input("type: \n1 to add\n2 to subtract\n3 to multiple\n4 to divide\n5 to average\n6 to shoplist_calculator \n>_ ")
- if command == "1" or command == "add":
- print("I am going to add the numbers together")
- num1 = int(input("Enter a number >_ "))
- num2 = int(input("Enter another number>_ "))
- add = num1 + num2
- result_add = str(add)
- print("The total of the two numbers is > " + result_add)
- elif command == "2" or command == "subtract":
- print("I am going to subtract the second number from first number")
- num1 = int(input("Enter the first number >_ "))
- num2 = int(input("Enter the second number>_ "))
- subt = num1 - num2
- result_sub = str(subt)
- print("Subtracting", num2, " from ", num1, " gives a difference of >_ " + result_sub)
- elif command == "3" or command == "multiply":
- print("I am going to multiply the two numbers")
- num1 = int(input("Enter the first number >_ "))
- num2 = int(input("Enter the second number>_ "))
- mult = num1 * num2
- result_mult = str(mult)
- print("The product of ", num1, " and ", num2, " gives >_ " + result_mult)
- elif command == "4" or command == "divide":
- print("I am going to divide your two numbers")
- num1 = int(input("Enter the numerator number >_ "))
- num2 = int(input("Enter the denominator number>_ "))
- div = num1 / num2
- result_div = str(div)
- print("The quotient from dividing ", num1, " by ", num2, " gives >_ " + result_div)
- elif command == "5" or command == "average":
- total = 0
- count = 0
- numNumbers = int(input("How many numbers do you want to average > "))
- for count in range(numNumbers):
- numEntered = input("Enter a number to include in your average " +str(count + 1) + "> ")
- total = total + int(numEntered)
- average = total / numNumbers
- print("The average of the ", numNumbers, " numbers entered is " + str(average))
- elif command == "6" or command == "shoplist_calculator":
- print("\nI will take a list of shopping items, their price and calculate a a running total for you")
- shopping = []
- count = 0
- total =0.0
- count = int(input("How many items do you want to include in your shopping list > "))
- for item in range(count):
- listitem = input("\nEnter item for your shopping list item number " +str(item + 1) + "> ")
- shopping.append(listitem)
- itemcost = input("Enter the cost of the item " +str(item + 1) + "> ")
- total = total + float(itemcost) #could place price in list so could output next to item
- print("\nto confirm, this is your list:") # new line to separate list
- for item in shopping: #now to print the list
- print ("\t\t\t\t\t",item) #adding tabs to indent the list of items
- total_items=len(shopping)
- print ("\nYou have " + str(total_items) + " items in your shopping list")
- print("and the total cost of the items entered is £ " + str(total))
- else:
- print("Sorry I don't understand")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement