crzcas

loop in my bot

Dec 4th, 2020 (edited)
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.04 KB | None | 0 0
  1. import math
  2.  
  3. finished = False
  4. while finished == False:
  5.    
  6.     print()
  7.     print("Hi, I am Atom, your personal bot.")
  8.     print("You can select one word of the menu, writing the word:")
  9.     print("add   subtract   multiply   divide   volume   average   shopping   bye")
  10.     command = input("How can I help you? ")
  11.  
  12.     # This if works when the word of the menu is wrong, giving a message "Sorry, I don't understand."    
  13.     if command !="add" and command !="subtract" and command !="multiply" and command !="divide" and command !="volume" and command !="average" and command !="shopping" and command != "bye":
  14.         print("Sorry, I don't understand.")
  15.  
  16.     elif command == "add" or command == "plus":   # Adding code to add in lines 16-24
  17.         print("lets add two numbers")
  18.         input1 = input("Number 1> ")
  19.         input2 = input("Number 2> ")
  20.         number1 = float(input1)
  21.         number2 = float(input2)
  22.         result = number1 + number2
  23.         output = str(result)
  24.         print(input1 + " + " + input2 + " = " + output)
  25.  
  26.     elif command == "subtract":   # Adding code to subtract in lines 26-34
  27.         print("lets subtract two numbers")
  28.         input1 = input("Number 1> ")
  29.         input2 = input("Number 2> ")
  30.         number1 = float(input1)
  31.         number2 = float(input2)
  32.         result = number1 - number2
  33.         output = str(result)
  34.         print(input1 + " - " + input2 + " = " + output)
  35.  
  36.     elif command == "multiply" or command == "multiplication":   # Adding code to multiply in lines 36-44
  37.         print("lets multiply two numbers")
  38.         input1 = input("Number 1> ")
  39.         input2 = input("Number 2> ")
  40.         number1 = float(input1)
  41.         number2 = float(input2)
  42.         result = number1 * number2
  43.         output = str(result)
  44.         print(input1 + " * " + input2 + " = " + output)
  45.  
  46.     elif command == "divide" or command == "division":   # Adding code to divide in lines 46-54
  47.         print("lets divide two numbers")
  48.         input1 = input("Number 1> ")
  49.         input2 = input("Number 2> ")
  50.         number1 = float(input1)
  51.         number2 = float(input2)
  52.         result = number1 / number2
  53.         output = str(result)
  54.         print(input1 + " / " + input2 + " = " + output)
  55.  
  56.     elif command == "Volume" or command == "volume":   # Adding code to volume in lines 56-65
  57.         print("lets calculate volume of cylinder with 2 values, ratio and high in cms.")
  58.         input1 = input("ratio > ")
  59.         input2 = input("high > ")
  60.         ratio = float(input1)
  61.         high = float(input2)
  62.         #pi1 = 3.14
  63.         result = math.pi * ratio * ratio * high
  64.         output = str(result)
  65.         print("volume of cylinder = " + output + " cms^3")
  66.  
  67.     elif command == "average" or command == "Average":   # Adding code to average in lines 67-76
  68.         print("lets calculate the average of some numbers!")
  69.         how_many = input("How many numbers > ")
  70.         how_many = int(how_many)
  71.         total = 0
  72.         for number_count in range(how_many):
  73.             number = input("Enter number " + str(number_count + 1) + "> ")
  74.             total = total + int(number)
  75.         result = total/ how_many
  76.         print("the average = " + str(result))
  77.  
  78.     elif command == "shopping" or command == "Shopping":   # Adding code to shopping in lines 78-92
  79.         shopping = []
  80.         how_many = input("how many items of shopping do you have? ")
  81.         how_many = int(how_many)
  82.         total = 0
  83.         for item_number in range (how_many):
  84.             item = input("What is the value of item " + str(item_number + 1) + "? ")
  85.             shopping.append(item)
  86.             total = total + float(item)
  87.         print(shopping)
  88.         print("Total shopping = " + str(total))
  89.  
  90.         for item in shopping:
  91.             print(item)
  92.         print("You have " + str(len(shopping)) + " items in your shopping list" + " and the total shopping is = " + str(total))
  93.    
  94.     else:
  95.         if command == "bye" or command == "Bye":
  96.             finished = True
  97.             print("session finished")
  98.  
  99. print("Bye")        
Advertisement
Add Comment
Please, Sign In to add comment