-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathTempConvert.py
More file actions
executable file
·30 lines (22 loc) · 2.05 KB
/
Copy pathTempConvert.py
File metadata and controls
executable file
·30 lines (22 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/env python
# -*- coding:utf-8 -*-
__author__ = 'MFC'
__time__ = '2019-03-21 01:57'
"""
https://www.icourse163.org/learn/BIT-268001?tid=1206073223#/learn/content?type=detail&id=1210530382&cid=1212669635
1.3实例1:温度转换
温度的刻画有两个不同体系:摄氏度(Celsius)和华氏度(Fahrenheit)。
请编写程序将用户输入华氏度转换为摄氏度,或将输入的摄氏度转换为华氏度。
转换算法如下:(C表示摄氏度、F表示华氏度)
C = ( F - 32 ) / 1.8
F = C * 1.8 + 32
"""
TempStr = input("请输入带有符号的温度值:")
if TempStr[-1] in ['F', 'f']: # 这个地方的写法不只一种
C = (eval(TempStr[0:-1]) - 32) / 1.8
print("转换后的温度是{:.2f}C".format(C))
elif TempStr[-1] in ['C', 'c']:
F = 1.8 * eval(TempStr[0:-1]) + 32
print("转换后的温度是{:.2f}F".format(F))
else:
print("输入格式错误")