年の入力値が2の場合、最初の12ヶ月間は1年、次の12ヶ月間は2年目にプログラムを表示するにはどうすればよいですか?ネストされたループ計算の出力が正しくないが、プログラムが実行される
また、計算がうまくいかないこともわかりません。私の所望の出力によると、総雨量出力は37でなければなりませんが、私はprint文の前に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()
あなたは何のための 'years_rain'を使用していません。 'year 1'の代わりにそれを印刷してみてください。 –
私は構文エラーのために私をさせてくれません。 – Alina
構文エラーとは何ですか?コードは何ですか?それを質問に入れてください。 –