import re
content = {‘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):10C
F=9/5*10.0+32=50.0F