crzcas

average and shopping function

Dec 13th, 2020 (edited)
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.79 KB | None | 0 0
  1. def do_average_and_shopping():
  2.     count = 0
  3.     data = []
  4.     how_many = input("how many numbers> ")
  5.     how_many = int(how_many)
  6.     for number_count in range(how_many):
  7.         number = input("Enter number " + str(number_count) +"> ")
  8.         number = float(number)
  9.         data.append(number)
  10.         count = count + 1
  11. #
  12.     total = 0
  13.     for number in data:
  14.         total = total + number
  15. #
  16.     if command == "shopping":
  17.         result=total
  18.     elif command== "average":
  19.         result=total/count
  20. #
  21.     if command == "shopping":
  22.         print("total is " + str(result) )
  23.     elif(command=="average"):
  24.         print("average is " + str(result) )
  25.        
  26.  
  27.  
  28. command = input("What operation do you want (average or shopping)?")
  29. # Run def
  30. do_average_and_shopping()    
  31.        
Advertisement
Add Comment
Please, Sign In to add comment