您的位置:首页 > 编程语言

代码清单5-3 使用raw_input()转换温度

2013-06-09 19:38 253 查看
print "This program converts Fahrenheit to Celsius"
print "Type in a temperature in Fahrenheir:",
fahrenheir=float(raw_input())#使用float(raw_input())从用户得到温度(华氏)
celsius=(fahrenheir-32)*5.0/9
print "That is",celsius,"degrees Celsius"


运行结果:

>>> ================================ RESTART ================================
>>>
This program converts Fahrenheit to Celsius
Type in a temperature in Fahrenheir: 89
That is 31.6666666667 degrees Celsius
>>>


其实input()函数也能实现。但是Python的将来版本(3.0及以后版本)去除了input()函数,只会有raw_input()。。。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: