首页 > 解决方案 > 你能看一下下面的代码吗,它不起作用并弹出:“TypeError: unsupported operand type(s) for /: 'str' and 'int'”。请

问题描述

你的老师要求你将大量的温度读数从摄氏温度转换为华氏温度。他们为您提供了使用公式:F = C * 9/5 + 32
C 是以摄氏度为单位测量的温度 F 是温度是华氏度

我的代码:

c = input("celsius: ") 
f = c*9/5+32
print(c," degrees Celcius is ",f," degrees fahrenheit")

标签: pythonstringintegertypeerror

解决方案


f = int(c)*9/5+32

这应该可以将摄氏温度转换为华氏温度,但这只是一个近似值......


推荐阅读