elena_gancedo

New_command_list

Jun 29th, 2019
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.65 KB | None | 0 0
  1. # I will include the shopping list creator into my bot
  2. print("Hi, I am Eley, your personal bot.")
  3. question1 = input("Do you want to chat with me?")
  4. print(question1)
  5. print("Let’s get started")
  6. users_name = input("What is your name? ")
  7. print(users_name)
  8. print("Nice to meet you " + users_name + ", welcome.")
  9. shopping = [] # Let's create an empty list variable
  10. how_many = input("How many items of shopping are needed? ")
  11. how_many = int(how_many)
  12. for item_number in range(how_many): # Let's add a "for" loop with a range to loop x times
  13.     item = input("What is item number " + str(item_number) + "? ") #
  14.     shopping.append(item) # Let's append item to the list
  15. print(shopping) # After the "for" loop let’s print the lista
  16. # Another way to show a total at the end
  17. print "The items in my shopping account are",len (shopping)
  18. count = 0
  19. for item in shopping:
  20.     print(item)
  21.     count = count + 1 # Counter
  22.     print(count)
  23. # Add up the cost of your shopping
  24. command = input("Let's calculate the cost of your shopping, select add/plus, average, discount, divide: ")
  25. if command == "add" or command == "plus":
  26.     result = how_many
  27.     output = str(result)
  28.     print("The items in my shopping account are " + output)
  29.     how_many = input("Please re-enter the number of items from your shopping list > ")
  30.     how_many = int(how_many)
  31.     total = 0
  32.     for number_count in range(how_many):
  33.         number = input("Enter the price of each item " + str(number_count) + "> ")
  34.         total = total + int(number)
  35.         result = total
  36.     print("The sum of all items of shopping account = " + str(result) + " €")
  37. # Average the cost of your shopping    
  38. elif command == "average":
  39.     result = how_many
  40.     output = str(result)
  41.     print("The items in my shopping account are " + output)
  42.     how_many = input("Please re-enter the number of items from your shopping list > ")
  43.     how_many = int(how_many)
  44.     total = 0
  45.     for number_count in range(how_many):
  46.         number = input("Enter the price of each item " + str(number_count) + "> ")
  47.         total = total + int(number)
  48.     result = total / how_many
  49.     print("The average of all items of shopping account = " + str(result) + " €")
  50. # Calculate a discount from the shopping list:
  51. # 1 Divide the discount percentage by 100 to convert it to a decimal. Eg: If the discount we want to calculate is 40%,
  52. # you must divide 40/100 = 0.4
  53. # 2 Multiply the discount converted to a decimal by the original price, in this way you will be able to find the discount
  54. # percentage.
  55. # Eg: If the original price is € 120, the operation to be performed will be 120 x 0.4 = € 48
  56. # 3 Subtract from the original price the discount amount we have obtained. Eg: If € 48 is the 40% discount of € 120, to
  57. # find the final price we must subtract the amount less than the highest: 120-48 = € 72
  58. elif command == "discount":
  59.     result = how_many
  60.     output = str(result)
  61.     print("The items in my shopping account are " + output)
  62.     how_many = input("Please re-enter the number of items from your shopping list > ")
  63.     how_many = int(how_many)
  64.     total = 0
  65.     for number_count in range(how_many):
  66.         number = input("Enter the price of each item " + str(number_count) + "> ")
  67.         total = total + int(number)
  68.     result = total
  69.     discount = input("Please enter the discount of shopping account > ")
  70.     percent = int(discount)
  71.     #number = int(100)
  72.     result1 = percent / 100
  73.     result2 = result1 * result
  74.     substract = result - result2
  75.     print("The discount of all items of shopping account = " + str(substract) + " €")
  76. else:
  77.     print("Sorry, because your answer is wrong, the chat is over.")
Add Comment
Please, Sign In to add comment