最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

基于Python實現(xiàn)溫度轉(zhuǎn)換程序

 更新時間:2023年10月07日 11:11:30   作者:星塵庫  
這篇文章主要為大家詳細介紹了如何基于Python實現(xiàn)簡單的溫度轉(zhuǎn)換程序,文中的示例代碼講解詳細,感興趣的小伙伴可以跟隨小編一起學習一下

1.使用pycharm運行溫度轉(zhuǎn)換程序,嘗試將溫度單位設(shè)在前面

2.參照溫度轉(zhuǎn)換程序,自己寫一個關(guān)于貨幣轉(zhuǎn)換、長度轉(zhuǎn)換、重量轉(zhuǎn)換或者面積轉(zhuǎn)換的程序

循環(huán)+函數(shù)

def convertemperature():
    temperature = ""
    while (temperature != "q"):
        temperature = input("請輸入帶有符號的溫度:")
        if (temperature[-1] in ['f', 'F']):
            C = (eval(temperature[0:-1]) - 32) / 1.8
            print("轉(zhuǎn)換后的溫度是{:.2f}C".format(C))
            print("退出請輸入q")
        elif (temperature[-1] in ['c', 'C']):
            C = (1.8 * eval(temperature[0:-1]) + 32)
            print("轉(zhuǎn)換后的溫度是{:.2f}C".format(C))
        else:
            print("輸入格式錯誤")
            print("退出請輸入q")
convertemperature()

循環(huán) +異常處理 溫度單位設(shè)在前面 f代表華氏度 c代表攝氏度---函數(shù)里面循環(huán)

def convertemperature():
    temperature = ""
    while (temperature != "exit"):
        temperature = input("請輸入帶有符號的溫度:")
        if (temperature[0] in ['f', 'F']):
            try:
                C = (eval(temperature[1:]) - 32) / 1.8
                print("轉(zhuǎn)換后的溫度是{:.2f}C".format(C))
            except:
                print("轉(zhuǎn)換失敗,請重新輸入")
            print("退出請輸入exit")
        elif (temperature[0] in ['c', 'C']):
            try:
                C = (1.8 * eval(temperature[1:]) + 32)
                print("轉(zhuǎn)換后的溫度是{:.2f}C".format(C))
            except:
                print("轉(zhuǎn)換失敗,請重新輸入")
            print("退出請輸入exit")
        else:
            print("輸入格式錯誤")
            print("退出請輸入exit")
    # 循環(huán) +異常處理 溫度單位設(shè)在前面 f代表華氏度 c代表攝氏度
convertemperature()

循環(huán)里面使用函數(shù)

temperature=""
while (temperature != "q"):
    temperature = input("請輸入帶有符號的溫度:")
    convertemperature2(temperature)
    def convertemperature2(aa):
        temperature = aa
        if (temperature[0] in ['f', 'F']):
            try:
                C = (eval(temperature[1:]) - 32) / 1.8
                print("轉(zhuǎn)換后的溫度是{:.2f}C".format(C))
            except:
                print("轉(zhuǎn)換失敗,請重新輸入")
            print("退出請輸入q")
        elif (temperature[0] in ['c', 'C']):
            try:
                C = (1.8 * eval(temperature[1:]) + 32)
                print("轉(zhuǎn)換后的溫度是{:.2f}C".format(C))
            except:
                print("轉(zhuǎn)換失敗,請重新輸入")
            print("退出請輸入q")
        else:
            print("輸入格式錯誤")
            print("退出請輸入q")

重量轉(zhuǎn)換

# 貨幣轉(zhuǎn)換、長度轉(zhuǎn)換 、重量轉(zhuǎn)換或者面積轉(zhuǎn)換
temperature = ""
while temperature != "q":
    temperature = input("請輸入帶有符號的重量:")
    print(temperature[-2:])
    if temperature[-2:] in ['kg', "Kg", "KG", "kG"]:
        try:
            C = (eval(temperature[0:-2])  * 1000)
            print("轉(zhuǎn)換后的重量是{:.2f}克".format(C))
        except:
            print("轉(zhuǎn)換失敗,請重新輸入")
        print("退出請輸入q")
    elif temperature[-1] in ['g', 'G']:
        try:
            C = (eval(temperature[0:-1]) / 1000)
            print("轉(zhuǎn)換后的重量是{:.2f}千克".format(C))
        except:
            print("轉(zhuǎn)換失敗,請重新輸入")
        print("退出請輸入q")
    else:
        print("輸入格式錯誤")
        print("退出請輸入q")
# 循環(huán) +異常處理  重量轉(zhuǎn)換

模仿例子程序,編寫英寸和厘米的轉(zhuǎn)換程序,1inch=2.54cm。比如,輸入3.2i則輸出8.13 c,輸入4.5c則輸出1.77i,輸入4.5k輸出“輸入格式錯誤”。

temperature = ""
while temperature != "q":
    temperature = input("請輸入帶有符號的尺寸:eg:3.2i \n")
    if temperature[-1:]    in ['i', 'I']:
        try:
            C = (eval(temperature[0:-1])  * 2.54)
            print("轉(zhuǎn)換后是{:.2f}c".format(C))
        except:
            print("轉(zhuǎn)換失敗,請重新輸入")
        print("退出請輸入q")
    elif temperature[-1] in ['c', 'C']:
        try:
            C = (eval(temperature[0:-1]) / 2.54)
            print("轉(zhuǎn)換后是{:.2f}i".format(C))
        except:
            print("轉(zhuǎn)換失敗,請重新輸入")
        print("退出請輸入q")
    else:
        print("輸入格式錯誤")
        print("退出請輸入q")

到此這篇關(guān)于基于Python實現(xiàn)溫度轉(zhuǎn)換程序的文章就介紹到這了,更多相關(guān)Python溫度轉(zhuǎn)換內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • python django 實現(xiàn)驗證碼的功能實例代碼

    python django 實現(xiàn)驗證碼的功能實例代碼

    本篇文章主要介紹了python django 實現(xiàn)驗證碼的功能實例代碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-05-05
  • python可視化 matplotlib畫圖使用colorbar工具自定義顏色

    python可視化 matplotlib畫圖使用colorbar工具自定義顏色

    這篇文章主要介紹了python可視化 matplotlib畫圖使用colorbar工具自定義顏色,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2020-12-12
  • Python常用模塊sys,os,time,random功能與用法實例分析

    Python常用模塊sys,os,time,random功能與用法實例分析

    這篇文章主要介紹了Python常用模塊sys,os,time,random功能與用法,結(jié)合實例形式分析了Python模塊sys,os,time,random功能、原理、相關(guān)模塊函數(shù)、使用技巧與操作注意事項,需要的朋友可以參考下
    2020-01-01
  • 用python編寫第一個IDA插件的實例

    用python編寫第一個IDA插件的實例

    今天小編就為大家分享一篇用python編寫第一個IDA插件的實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-05-05
  • Python報錯TypeError: unhashable type: ‘numpy.ndarray‘的解決辦法

    Python報錯TypeError: unhashable type: ‘numpy.nd

    在Python編程中,尤其是在處理數(shù)據(jù)時,我們經(jīng)常使用numpy數(shù)組,然而,當我們嘗試將numpy數(shù)組用作字典的鍵或集合的元素時,就會遇到TypeError: unhashable type: 'numpy.ndarray',本文將探討這個錯誤的原因,并給出幾種可能的解決方案,需要的朋友可以參考下
    2024-09-09
  • python requests證書問題解決

    python requests證書問題解決

    這篇文章主要介紹了python requests證書問題解決,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2019-09-09
  • 詳解django實現(xiàn)自定義manage命令的擴展

    詳解django實現(xiàn)自定義manage命令的擴展

    這篇文章主要介紹了django實現(xiàn)自定義manage命令的擴展,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2019-08-08
  • networkx庫繪制帶權(quán)圖給無權(quán)圖加權(quán)重輸出

    networkx庫繪制帶權(quán)圖給無權(quán)圖加權(quán)重輸出

    這篇文章主要為大家介紹了Python?networkx庫繪制帶權(quán)圖給無權(quán)圖加權(quán)重并輸出權(quán)重的示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-05-05
  • python中的hashlib和base64加密模塊使用實例

    python中的hashlib和base64加密模塊使用實例

    這篇文章主要介紹了python中的hashlib和base64加密模塊使用實例,hashlib模塊支持的加密算法有md5 sha1 sha224 sha256 sha384 sha512,需要的朋友可以參考下
    2014-09-09
  • Python控制臺輸出俄羅斯方塊移動和旋轉(zhuǎn)功能

    Python控制臺輸出俄羅斯方塊移動和旋轉(zhuǎn)功能

    這篇文章主要介紹了Python控制臺輸出俄羅斯方塊移動和旋轉(zhuǎn)功能,本文通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2021-04-04

最新評論

镇雄县| 墨脱县| 合阳县| 南丹县| 纳雍县| 定州市| 调兵山市| 郓城县| 凤冈县| 东阿县| 永嘉县| 本溪市| 达日县| 汝州市| 松江区| 隆子县| 徐闻县| 阜平县| 鸡东县| 轮台县| 尤溪县| 沙湾县| 杂多县| 称多县| 柞水县| 永康市| 定西市| 巴彦淖尔市| 阳泉市| 青岛市| 西贡区| 仪征市| 柳州市| 玛沁县| 綦江县| 夏河县| 右玉县| 深水埗区| 襄汾县| 华池县| 化州市|