Python Forum
Simple averaging program
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Simple averaging program
#1
Probably the most convoluted way to find the average of a set of numbers in Python but here it is.

amount = int(input("Enter number of items: "))#Gets amount of numbers to be averaged
q = "q"
for x in range(1, amount):#This generates as many variables as there are numbers to be averaged
       q = str(x) + q
q = list(q)
for x in range(0, amount):#This sets each variable to the user's input
       q[x] = input("Enter number: ")
sum = 0
for x in range(0, amount):#This finds the sum of all the numbers
       sum = int(q[x]) + sum
average = sum / amount#This finds the average by dividing the sum and the total amount of numbers
print(average)
Reply


Messages In This Thread
Simple averaging program - by Iskuss - Jun-05-2017, 03:07 AM
RE: Simple averaging program - by micseydel - Jun-05-2017, 05:43 AM
RE: Simple averaging program - by nilamo - Jun-07-2017, 06:23 PM
RE: Simple averaging program - by micseydel - Jun-07-2017, 06:40 PM
RE: Simple averaging program - by nilamo - Jun-07-2017, 06:46 PM
RE: Simple averaging program - by Mekire - Jun-09-2017, 12:44 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020