elena_gancedo

total_count-average

Jul 12th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.17 KB | None | 0 0
  1. calc = []  
  2. # function
  3. def calculation(operation):
  4.     how_many = input("How many numbers? ")
  5.     how_many = int(how_many)
  6.     total = (0)
  7.     for user_number in range(how_many):
  8.         number = input("Enter number " + str(user_number + 1) + ": ")
  9.         calc.append(number)
  10.         len(calc)
  11.         result = str(len(calc))# Function "len"
  12.         total = total + int(number)
  13.     if operation == "total":
  14.         print ("I have " + result + " numbers in my list")
  15.         print("The sum total of numbers is " + str(total))
  16.     else:
  17.         result = total / how_many
  18.         print("The average is " + str(result))
  19.     return
  20. # main
  21. print("I am Eley, your personal bot.")
  22. users_name = input("What is your name?")
  23. print("Hi "+users_name + ", nice to meet you. ")
  24. print("Let's do some maths:")  
  25. # loop  
  26. finished = False
  27. while finished == False:
  28.     operation = input("What operation would you like 'total' or 'average'? :  ")
  29.     if operation in  ["total","average"]:
  30.         calculation(operation)
  31.     elif operation == "bye":
  32.         finished = True
  33.         print("See you again")
  34.     else:
  35.         print("I'm sorry, I don't understand " + operation)
Advertisement
Add Comment
Please, Sign In to add comment