国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 罗江县| 晋州市| 巴南区| 金寨县| 南江县| 积石山| 嘉黎县| 花莲市| 汤原县| 墨脱县| 花莲市| 尼木县| 盐池县| 石棉县| 广德县| 盘山县| 噶尔县| 凌海市| 扎赉特旗| 昆山市| 罗定市| 双流县| 达州市| 鹤庆县| 福鼎市| 灯塔市| 南和县| 沙坪坝区| 唐河县| 辉县市| 庄浪县| 新昌县| 和硕县| 南昌县| 锦屏县| 元朗区| 巴楚县| 嘉祥县| 十堰市| 南漳县| 瓦房店市|