【发布时间】:2019-03-15 11:59:39
【问题描述】:
这是我现在要使用的代码。当我运行它时,一切都很好,接受所有温度时它不会打印任何东西,但会给我错误,“TypeError:必须是 str,而不是 float”。
#temperature, kian, Thursday/March/14, working with variables.
#this code is going to ask for a temperature in celsius then it will turn celsius temperature into fahrenheit.
celsius = float(input('what is the temperature in celsius? '))
((9.0 / 5.0) * celsius + 32.0)
#this code will ask for a temperature in fahrenheit and then will convert it into celsius.
fahrenheit = float(input('Enter a temperature in Fahrenheit. '))
(5.0 * (fahrenheit - 32.0)) / 9.0
#these prints should print out what was converted but there is an error of needing it to be a str not a float.
print ('the fahrenheit from celsius is, ' + celsius)
print ('the celsius from fahrenheit is, ' + fahrenheit)
提前感谢大家的帮助。
【问题讨论】:
-
打印时需要将
celsius和fahrenheit转换成字符串 -
((9.0 / 5.0) * celsius + 32.0)这个statemebnt没有效果...
标签: python