Advertisement
Guest User

Untitled

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