Advertisement
Guest User

Untitled

a guest
Feb 21st, 2020
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.85 KB | None | 0 0
  1. finished = False
  2. while finished == False:
  3.  
  4.     #Greeting
  5.     print("Hi, I am Marvin, your personal bot.")
  6.  
  7.     #Ask the user for a command
  8.     command = input("How can I help? ")
  9.  
  10.     #Check for addition command
  11.  
  12.     if command == "add" or command == "plus" or command == "Add" or command == "Plus":
  13.         print("let's add some numbers")
  14.         input1 = input("Number 1> ")
  15.         input2 = input("Number 2> ")
  16.         number1 = int(input1)
  17.         number2 = int(input2)
  18.         result = number1 + number2
  19.         output = str(result)
  20.         print(input1 + " + " + input2 + " = " + output)
  21.  
  22.     #Check for subtraction command 
  23.  
  24.     elif command == "subtract" or command == "take" or command == "Subtract" or command == "Take":
  25.         print("let's subtract some numbers")
  26.         input1 = input("Number 1> ")
  27.         input2 = input("Number 2> ")
  28.         number1 = int(input1)
  29.         number2 = int(input2)
  30.         result = number1 - number2
  31.         output = str(result)
  32.         print(input1 + " - " + input2 + " = " + output)
  33.  
  34.     #Check for division command
  35.  
  36.     elif command == "divide" or command == "Divide":
  37.         print("let's divide some numbers")
  38.         input1 = input("Number 1> ")
  39.         input2 = input("Number 2> ")
  40.         number1 = int(input1)
  41.         number2 = int(input2)
  42.         result = number1 / number2
  43.         output = str(result)
  44.         print(input1 + " / " + input2 + " = " + output)
  45.        
  46.     #Check for multiply command
  47.  
  48.     elif command == "multiply" or command == "Multiply" or command == "times" or command == "Times":
  49.         print("let's multiply some numbers")
  50.         input1 = input("Number 1> ")
  51.         input2 = input("Number 2> ")
  52.         number1 = int(input1)
  53.         number2 = int(input2)
  54.         result = number1 * number2
  55.         output = str(result)
  56.         print(input1 + " x " + input2 + " = " + output)
  57.  
  58.  
  59.     #Check for average command
  60.  
  61.     elif command == "average" or command == "Average":
  62.         print("let's work out an average")
  63.         how_many = input("How many numbers would you like to average?> ")
  64.         how_many = int(how_many)
  65.         total = 0
  66.         number_list=[]
  67.         for number_count in range(how_many):
  68.             number = input("Enter number " + str(number_count+1) + "> ")
  69.             total = total + int(number)
  70.             number_list.append(number)
  71.         result = total / how_many
  72.         print("here are the numbers you wanted to average")
  73.         for item in number_list:
  74.             print(item)
  75.         print("the average of those numbers = " +str(result))
  76.        
  77.     #Check for shopping list command
  78.  
  79.     elif command == "shopping" or command == "Shopping":
  80.         #Create a shopping list calculator with given number of items based on user input and display it on screen
  81.        
  82.         shopping =[]
  83.  
  84.         how_many = input("how many items of shopping do you have? ")
  85.         how_many_items = int(how_many)
  86.  
  87.         for item in range(how_many_items):
  88.             new_item = input("Enter item number " + str(item+1) + " in the shopping list > ")
  89.             shopping.append(new_item)
  90.  
  91.         #Print out the items
  92.        
  93.         for item in shopping:
  94.             print(item)
  95.  
  96.         print("You added " + how_many + " items to the list")
  97.        
  98.         print("now let's calculate how much that will cost you!")
  99.        
  100.         total_cost=0
  101.        
  102.         for item in shopping:
  103.             item_cost=input("how much is the item " + item + " in £ ? >")
  104.             total_cost=total_cost+float(item_cost)
  105.        
  106.         print("the total cost of your shopping is £" + str(total_cost))
  107.        
  108.    
  109.     elif command == "bye" or command == "Bye":
  110.         finished = True
  111.    
  112.        
  113.     #Error handling for unknown commands
  114.  
  115.     else:
  116.         print("Sorry, I don't understand")
  117.        
  118.  
  119. print("Bye! Hope I was helpful!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement