Pythonでループを学習し、私が使用している本は「while」ステートメントを導入したばかりで、イントロプログラミングクラスの問題を行っています。ユーザー入力を摂氏で取得し、それを華氏に変換し、変換された温度の合計を合計する必要があります、私の疑似コードでは理にかなっていますが、「while」ステートメントの適用に問題があります。これまでのところこのコードがあり、この種のループを行う簡単な方法があるかどうか疑問に思っていますが、構文が機能していませんアプリケーション用。ここまでのコードです。また、この問題では、-999 をセンチネルとして使用してプログラムを終了し、合計 (温度の華氏変換の合計と変換された温度の合計) を表示するよう求められます。
sum = 0 #start counter at zero?
temp = raw_input('enter temp in celsius, enter -999 to exit: ') #ask user for temp
while temp != -999: #my while statement, sentinel is -999
faren = 9 * temp / 5 + 32
sum += temp #to accumulate the sum of temps?
total = sum + temp #for the total, does this go below?
print raw_input('enter temp in celcius, enter -999 to exit: ') #the loop for getting another user temp
print faren #totals would be displayed here if user enters -999
print total
#need to use the "break" statment?