当前位置:   article > 正文

《python语言程序设计基础》嵩天著-第2章程序练习题答案_python程序练习题2.1答案

python程序练习题2.1答案

练习题代码

正在看书自学中,贴出自己的作业,欢迎大家交流指正,一起进步~

2.1 实例1的修改

# TempConvert
def TempConvert(value):    
    if tempstr[-1] in ['F','f']:
        c = (eval(tempstr[0:-1]) - 32)/1.8
        print ("The temperature is converted to {}C".format(int(c)))
    elif tempstr[-1] in ['C','c']:
        f = eval(tempstr[0:-1])*1.8 + 32
        print("The temperature is converted to {}F".format(int(f)))
    else:
        print("Input wrong!")
    
tempstr = input("pls input the temperature with unit F or C: ")
while tempstr[-1] not in ['N','n']:
    TempConvert(tempstr)
    tempstr = input(
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/833523
推荐阅读
相关标签
  

闽ICP备14008679号