ユーザー入力(温度)を取得するプログラムを作成する割り当てが与えられました。温度が摂氏の場合は華氏に、またはその逆に変換します。
問題は、35:Cのようなものを入力すると、myscaleがC my codeであっても、プログラムがelif myscale=="C"ではなくifmyscale=="F"を使用することです。
mytemp = 0.0
while mytemp != "quit":
info = raw_input("Please enter a temperature and a scale. For example - 75:F " \
"for 75 degrees farenheit or 63:C for 63 degrees celcius "\
"celcious. ").split(":")
mytemp = info[0]
myscale = str(info[1])
if mytemp == "quit":
"You have entered quit: "
else:
mytemp = float(mytemp)
scale = myscale
if myscale == "f" or "F":
newtemp = round((5.0/9.0*(mytemp-32)),3)
print "\n",mytemp,"degrees in farenheit is equal to",newtemp,"degrees in
celcius. \n"
elif: myscale == "c" or "C":
newtemp = 9.0/5.0*mytemp+32
print "\n",mytemp,"degrees in celcius is equal to",newtemp,"degrees in
farenheit. \n"
else:
print "There seems to have been an error; remember to place a colon (:)
between "\
"The degrees and the letter representing the scale enter code here. "
raw_input("Press enter to exit")