Jakob Williams Jakob Williams - 2 months ago 7
Python Question

Confused by results from simple calculation

I am not sure why the below code is not working. I am running this in python 3.5.2 and the problem appears to be in the calculation portion of the code. It returns no errors but gives huge values that shouldn't be the average of the 5 inputs.

#inputs
year1 = input("Enter wins for year 1: ")
year2 = input("Enter wins for year 2: ")
year3 = input("Enter wins for year 3: ")
year4 = input("Enter wins for year 4: ")
year5 = input("Enter wins for year 5: ")

#calculation
averageWin = int(year1 + year2 + year3 + year4 + year5) / 5
#output
print ("Average wins are", averageWin)

dee dee
Answer

Try this.

    year = 0
    for i in range(5):
        ann = "{:,.0f}".format(i+1)
        year=year+input("Enter wins for year "+ann+": ")
    print year/5.

Shorter and works.