私は検索しましたが、この問題がどのように発生するのか、またはそれを解決する方法を理解できません。どんな助けでもありがたいです、ありがとう。
私のコードは次のとおりです。
def main():
temperature = raw_input("Please enter an integer followed by a single space then either a F for Fahrenheit, C for Celsius, K for Kelvin, or R for Rankine: ")
# algorithm for Farenheit to Kelvin, Celsius, and Rankine
if temperature[-1] == "F":
K = (temperature[:-1] + (459.67) * (5.0/9.0))
print K
C = (temperature[:-1] - 32) * (5.0/9.0)
print C
R = (temperature[:-1] + 459.67)
print R
# algorithm for Celsius to Kelvin, Fahrenheit, and Rankine
elif temperature[-1] == "C":
K = (temperature[:-1] + 273.15)
print K
F = (temperature[:-1] * (9.0/5.0) + 32)
print F
R = (temperature[:-1] + 273.15) * (9.0/5.0)
print R
# algorithm for Kelvin to Celsius, Fahrenheit, and Rankine
elif temperature[-1] == "K":
C = (temperature[:-1] - 273.15)
print C
F = (temperature[:-1] * (9.0/5.0) - 459.67)
print F
R = (temperature[:-1] * (9.0/5.0))
print R
# algorith for Rankine to Fahrenheit, Celsius, and Kelvin
elif temperature[-1] == "R":
F = (temperature[:-1] - 459.67)
print F
C = (temperature[:-1] - 491.67) * (5.0/9.0)
print C
K = (temperature[:-1] * (5.0/9.0))
print K
main()
「50F」を入力した後のエラーメッセージ:
整数の後に単一のスペースを入力してから、華氏の場合はF、摂氏の場合はC、ケルビンの場合はK、ランキンの場合はRのいずれかを入力してください:50 F
Traceback (most recent call last):
File "/Users/Minotza/Documents/multi-unit_temperature_converter.py", line 36, in <module>
main()
File "/Users/Minotza/Documents/multi-unit_temperature_converter.py", line 5, in main
K = (temperature[:-1] + (459.67) * (5.0/9.0))
TypeError: cannot concatenate 'str' and 'float' objects
>>>