Advertisement
francydafne

my_last_bot

Dec 23rd, 2019
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.21 KB | None | 0 0
  1. def do_calculation():
  2.     print ("let's" + command + " some numbers")
  3.     input1 = input ("Number 1> ")
  4.     input2 = input ("Number 2> ")
  5.     number1 = int(input1)
  6.     number2 = int(input2)
  7.     if command == "add":
  8.         result = number1 + number2
  9.         operator = "+"
  10.     elif command == "subtract":
  11.         result = number1 - number2
  12.         operator = "-"
  13.     output = str(result)
  14.     print (input1 + operator + input2 + "=" + output)
  15.  
  16. def average_or_total():
  17.     total = 0
  18.     print ("Let's calculate the " + command + " of some numbers.")
  19.     how_many = input("How many numbers would you like " + command + " ? ")
  20.     how_many = int(how_many)
  21.     for n in range(how_many):
  22.         n = n + 1
  23.         number = input("Enter a number " + str(n) + ": ")
  24.         total = total + int(number)
  25.     if command == "average":
  26.         result = total/how_many
  27.     elif command == "total":
  28.         result = total + int(number)
  29.     print ("the " + command + " is " + str(result))
  30.  
  31. finished = False
  32. while finished == False:
  33.  
  34.     print ("Hello, I am francydafne, your bot!")
  35.     # code for adding numbers:
  36.     command = input ("How can I help? ")
  37.     if command == "add" or command == "plus":
  38.         do_calculation()
  39.     # code for subtracting numbers:
  40.     elif command == "subtract":
  41.         do_calculation()
  42.     # code for dividing numbers:
  43.     elif command == "divide":
  44.         print ("let's divide some numbers")
  45.         input1 = input ("Number 1> ")
  46.         input2 = input ("Number 2> ")
  47.         number1 = int(input1)
  48.         number2 = int(input2)
  49.         result = number1 / number2
  50.         output = str(result)
  51.         print (input1 + "/" + input2 + "=" + output)
  52.     # code for multiplying numbers:
  53.     elif command == "multiply":
  54.         print ("let's multiply some numbers")
  55.         input1 = input ("Number 1> ")
  56.         input2 = input ("Number 2> ")
  57.         number1 = int(input1)
  58.         number2 = int(input2)
  59.         result = number1 * number2
  60.         output = str(result)
  61.         print (input1 + "*" + input2 + "=" + output)
  62.     # code for calculating the area of a square:
  63.     elif command == "square area":
  64.         print ("let's calculate the area of a square multiplying its sides")
  65.         input1 = input ("Number 1> ")
  66.         input2 = input ("Number 2> ")
  67.         number1 = int(input1)
  68.         number2 = int(input2)
  69.         result = number1 * number2
  70.         output = str(result)
  71.         print (input1 + "*" + input2 + "=" + output)
  72.     # code for calculating averages or total
  73.     elif command == "average":
  74.         average_or_total()
  75.     elif command == "total":
  76.         average_or_total()
  77.     # code for listing things I do during the day
  78.     elif command == "todolist":
  79.         todolist = []
  80.         everyday = input ("How many things do you do? ")
  81.         everyday = int(everyday)
  82.         for acts in range(everyday):
  83.             actions = input("What do you do? " + str(acts+1) + " ")
  84.             todolist.append (actions)
  85.         print (todolist)
  86.         print ("The things I do every day are " + str(everyday))
  87.     # to stop the program:
  88.     elif command == "bye":
  89.         finished = True
  90.     # if everything goes wrong....
  91.     else:
  92.         print ("sorry, I don't understand")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement