案例:python實現單位轉換

來源:互聯網
上載者:User

標籤:python

import recontent = {‘T‘:‘溫度轉換‘, ‘L‘:‘長度轉換‘, ‘D‘:‘貨幣轉換‘ }for k,v in content.items(): print(k,v)switch_type = input(‘請輸入轉換類型:‘)if switch_type == ‘T‘: temp = input(‘請輸入溫度(樣本:1C或者1F):‘) if re.search(‘C‘,temp): temp = float(temp.strip(‘C‘)) Tf = (9/5)*temp + 32 print(f‘F=9/5*{temp}+32={Tf}F‘) elif re.search(‘F‘,temp): temp = float(temp.strip(‘F‘)) Tc = (5/9)*(temp - 32) print(f‘C=5/9*({temp}-32)={Tc}C‘) else: print(‘輸入有誤,樣本:1C或者1F‘)if switch_type == ‘L‘: temp = input(‘請輸入長度(樣本:1m或者1ft):‘) if re.search(‘m‘,temp): temp = float(temp.strip(‘m‘)) ft = 3.281*temp print(f‘ft=3.281*{temp}={ft}ft‘) elif re.search(‘ft‘,temp): temp = float(temp.strip(‘ft‘)) M = 0.3048*temp print(f‘M=3.281*{temp}={M}m‘) else: print(‘輸入有誤,樣本:1m或者1ft‘) if switch_type == ‘D‘: temp = input(‘請輸入貨幣(樣本:1美元或者1人民幣元):‘) if re.search(‘美元‘,temp): temp = float(temp.strip(‘美元‘)) RMB = 6.671*temp print(f‘RMB=6.671*{temp}={RMB}人民幣元‘) elif re.search(‘人民幣元‘,temp): temp = float(temp.strip(‘人民幣元‘)) dollar = 0.1499*temp print(f‘dollar=0.1499*{temp}={dollar}美元‘) else: print(‘輸入有誤,樣本:1美元或者1人民幣元‘)
T 溫度轉換L 長度轉換D 貨幣轉換請輸入轉換類型:T請輸入溫度(樣本:1C或者1F):10CF=9/5*10.0+32=50.0F

案例:python實現單位轉換

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.