国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

python實(shí)現(xiàn)簡單溫度轉(zhuǎn)換的方法

2020-02-23 00:20:03
字體:
供稿:網(wǎng)友

本文實(shí)例講述了python實(shí)現(xiàn)簡單溫度轉(zhuǎn)換的方法。分享給大家供大家參考。具體分析如下:

這是一段簡單的python代碼,用戶轉(zhuǎn)換不同單位的溫度,適合初學(xué)者參考
代碼如下:def c2f(t):
    return (t*9/5.0)+32
def c2k(t):
    return t+273.15
def f2c(t):
    return (t-32)*5.0/9
def f2k(t):
    return (t+459.67)*5.0/9
def k2c(t):
    return t-273.15
def k2f(t):
    return (t*9/5.0)-459.67
def get_user_input():
    user_input = 0
    while type(user_input) != type(1.0):
        user_input = raw_input("Enter degrees to convert: ")
        try:
            user_input = float(user_input)
        except:
            print user_input + " is not a valid entry"
    return user_input
def main():
    menu = "/nTemperature Convertor/n/n"+/
        "1. Celsius to Fahrenheit/n"+/
        "2. Celsius to Kelvin/n"+/
        "3. Fahrenheit to Celsius/n"+/
        "4. Fahrenheit to Kelvin/n"+/
        "5. Kelvin to Celsius/n"+/
            "6. Kelvin to Fahrenheit/n"+/
        "7. Quit"
    user_input = 0
    while user_input != 7:
        print menu
        user_input = raw_input("Please enter a valid selection: ")
        try:
            user_input = int(user_input)
        except:
            print user_input + " is not a valid selction, please try again/n"
        if user_input == 1:
            t = get_user_input()
            print str(t) + " degree Celsius is " + str((c2f(t))) + " degree Fahrenheit"
        elif user_input == 2:
            t = get_user_input()
            print str(t) + " degree Celsius is " + str((c2k(t))) + " degree Kelvin"

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 缙云县| 梅州市| 武川县| 巴青县| 昭觉县| 绥滨县| 尼玛县| 仁怀市| 高平市| 玉山县| 越西县| 雷山县| 白朗县| 蒙山县| 东莞市| 霍林郭勒市| 大渡口区| 三江| 钦州市| 淮阳县| 依安县| 什邡市| 泾川县| 徐汇区| 贺州市| 阿坝县| 班玛县| 延川县| 两当县| 河北省| 内丘县| 双柏县| 湘潭县| 临桂县| 平江县| 文登市| 宜州市| 玉林市| 万年县| 望江县| 昆山市|