python - unexpected TypeError: unsupported operand type(s) for +=: 'int' and 'str' -
the task write programme asks user come in total rainfall each of 12 months. inputs stored in list. programme should calculate , display total rainfall year, average monthly rainfall, , months highest , lowest amounts.
i supposed using loop loops 20 times , appends each score list after entered. please maintain in mind beginner. here's code far:
def main(): months = [0] * 12 name_months = ['jan','feb','mar','apr','may','jun', \ 'jul','aug','sep','oct','nov','dec'] def total(months): total = 0 num in months: total += num homecoming total index in range(12): print('please come in amount of rain in') months[index] = input(name_months[index] + ': ') print('the total is'), total(months),'mm.' avarage = total(months) / 12.0 print('the avarage rainfall is'), avarage,'mm.' main()
this must python 3. have convert user input numbers instead of strings:
# sets months[index] string months[index] = input(name_months[index] + ': ')
should be:
# sets months[index] (floating-point) number months[index] = float(input(name_months[index] + ': '))
python loops python-3.x
No comments:
Post a Comment