现在的位置: 首页 > 综合 > 正文

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

2012年11月19日 ⁄ 综合 ⁄ 共 470字 ⁄ 字号 评论关闭
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()。。。

抱歉!评论已关闭.