I have writen this but I don't know how to get the names of the months, it works if the months got a number that represents it in the list. I need help with the last thing. How do I change so it shows the name of the months instead?
# -*- coding: cp1252 -*- def main(): num_months = 12 #Definera lite listor months = [0] * num_months name_months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sept','Oct','Nov','Dec'] #Funktion för räkna det totala från listan def total(months): total = 0 for num in months: total += num return total #Få alla nummer från användaren for index in range(num_months): print 'Enter the amount of rain in', months[index] = input(str(index + 1) + ': ') print 'The total is', total(months), 'mm.' #Genomsnittet avarage = float(total(months)) / float(num_months) print 'The avarage rainfall is', avarage, 'mm.' #Översätt från siffror till månadernas namn #Sortera listan months.sort() print 'Lowest is', months[0] print 'Most is', months[11] main()

New Topic/Question
Reply




MultiQuote




|