>>> def main():
fahrenheit = eval(input("Enter the value for F: "))
celsius = fahrenheit - 32 * 5/9
print("The value from Fahrenheit to Celsius is " + celsius)
>>> main()
Enter the value for F: 32
Traceback (most recent call last):
File "<pyshell#73>", line 1, in <module>
main()
File "<pyshell#72>", line 4, in main
print("The value from Fahrenheit to Celsius is " + celsius)
TypeError: Can't convert 'float' object to str implicitly"
Run Code Online (Sandbox Code Playgroud)
Jay*_*hik 18
floats不能隐式转换为字符串.你需要明确地做.
print("The value from Fahrenheit to Celsius is " + str(celsius))
Run Code Online (Sandbox Code Playgroud)
但最好使用它format.
print("The value from Fahrenheit to Celsius is {0}".format(celsius))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
31495 次 |
| 最近记录: |