python 系统学习实例1.1 - 华氏度与摄氏度的转换

# C = ( F - 32 ) / 1.8‪‬‪‬‪‬‪‬‪‬‮‬‫‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬
# F = C * 1.8 + 32‪‬‪‬‪‬‪‬‪‬‮‬‫‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬

def tempConvert():
    t = input("请输入数值:")
    C = ["c","C"]
    F = ["F","f"]
    if t[0] in C:
        temp = (float(t[1:])*1.8) +32
        temp = "{:.2f}".format(temp)
        temp = "F" + str(temp)
        print("结果:",temp)
    elif t[0] in F:
        temp =(float(t[1:])-32)/1.8
        temp = "{:.2f}".format(temp)
        temp = "C" + str(temp)
        print("结果:",temp)
    else:
        print("输入格式错误")
        return False
    return temp


tempConvert()

猜你喜欢

转载自blog.csdn.net/weixin_39241397/article/details/82827993