我的将farenheight转换为摄氏度的代码有什么问题? [英] What's wrong with my code to convert farenheight to Celsius?

查看:98
本文介绍了我的将farenheight转换为摄氏度的代码有什么问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#Programme to covert Farenheight to Celcius
F=input("Enter Value:")

F=((F-32)/9)*5
       print("The temperature is ",F,"Degrees Celcius")

当我尝试运行它时,它说TypeError:-的不支持的操作数类型:"str"和"int"

When i try to run it it says TypeError: unsupported operand type(s) for -: 'str' and 'int'

推荐答案

将您输入的类型强制转换为整数

Type cast you input to an int

F=int(input("Enter Value:"))

并强制除法返回浮点数.将此添加到最顶部

And force the division to return a float. Add this at the very top

from __future__ import division

这篇关于我的将farenheight转换为摄氏度的代码有什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆