Wie kann ich mein Programm anzeigen Jahr 1 für die ersten 12 Monate und dann Jahr 2 für die nächsten 12 Monate anzeigen, wenn der Eingabewert für Jahre = 2?Nested Loops Berechnung Ausgabe ist falsch, aber das Programm läuft
Auch ich weiß nicht, wo meine Berechnung falsch läuft. Nach meinem gewünschten Ausgang sollte die Gesamtniederschlagsmenge Ausgang 37 sein, aber ich bin 39.
#the following are the values for input:
#year 1 month 1 THROUGH year 1 month 11 = 1
#year 1 month 12 THROUGH year 2 month 12 = 2
def main():
#desired year = 2
years = int(input("Enter the number of years you want the rainfall calculator to determine: "))
calcRainFall(years)
def calcRainFall(yearsF):
months = 12
grandTotal = 0.0
for years_rain in range(yearsF):
total= 0.0
for month in range(months):
print('Enter the number of inches of rainfall for year 1 month', month + 1, end='')
rain = int(input(': '))
total += rain
grandTotal += total
#This is not giving me the total I need. output should be 37.
#rainTotal = rain + grandTotal
#print("The total amount of inches of rainfall for 2 year(s), is", rainTotal)
print("The total amount of inches of rainfall for 2 year(s), is", grandTotal)
main()
Sie sind nicht 'years_rain' für alles verwenden. Versuchen Sie, es anstelle von "Jahr 1" zu drucken. –
das würde mich wegen eines Syntaxfehlers nicht lassen. – Alina
Was ist der Syntaxfehler und was ist der Code? Stellen Sie es in Frage. –