当前位置:网站首页>温度转换 II
温度转换 II
2022-06-29 02:12:00 【长街395】
描述
温度的刻画有两个不同体系:摄氏度(Celsius)和华氏度(Fabrenheit)。
请编写程序将用户输入华氏度转换为摄氏度,或将输入的摄氏度转换为华氏度。
转换算法如下:(C表示摄氏度、F表示华氏度)
C = ( F - 32 ) / 1.8
F = C * 1.8 + 32
要求如下:
(1) 输入输出的摄氏度采用大写字母C开头,温度可以是整数或小数,如:C12.34指摄氏度12.34度;
(2) 输入输出的华氏度采用大写字母F开头,温度可以是整数或小数,如:F87.65指华氏度87.65度;
(3) 不考虑异常输入的问题,输出保留小数点后两位;
(4) 使用input()获得测试用例输入时,不要增加提示字符串。
输入
示例1:C12.34
示例2:F87.65
输出
示例1:F54.21
示例2:C30.92
Tem=input()
if Tem[0] in ['F','f']:
t=((eval(Tem[1:])-32)/1.8)
print("C{:.2f}".format(t))
elif Tem[0] in ['C','c']:
t=((eval(Tem[1:]))*1.8+32)
print("F{:.2f}".format(t))请注意两点:
(1) 将输入字符串转换为数字时使用eval()函数,不要用int()函数,因为输入的数字可能不是整数;
(2) 采用{:.2f}将输出数字变成两位小数点表示时,即使数学上该输出值是整数,也会按照小数方式输出,例如,转换后温度为10度,输出为10.00。
边栏推荐
- Large scale visual relationship understanding
- [从零开始学习FPGA编程-50]:视野篇 - 芯片是如何被制造出来的?芯片制造的十三大步骤。
- Wechat campaign auto like
- SAP ui5 beginner tutorial 22 - development and use of filter
- Tiflash compiler oriented automatic vectorization acceleration
- Introduction to super dongle scheme
- [understanding of opportunity -33]: seeing is not necessarily true. Most of the time, "seeing is false"
- 微信运动自动点赞
- 利用kubernetes資源鎖完成自己的HA應用
- Use kubernetes resource lock to complete your own ha application
猜你喜欢
随机推荐
KOA Quick Start
Secondary encapsulation of storage (sessionstorage/localstorage) using TS
如何成为一名高级数字 IC 设计工程师(1-1)Verilog 编码语法篇:引言
Introduction to super dongle scheme
110. simple chat room 13: chat room server
2022.02.15
同花顺究竟是如何开户?现在网上开户安全么?
Live broadcast preview | can SQL also play industrial machine learning? Mlops meetup V3 takes you to the bottom!
A full screen gesture adaptation scheme
【Redis】SortedSet类型
项目研发,有哪些好用的免费脑图工具软件
Adding, deleting, checking and modifying stack - dynamic memory
How to manage device authorization
Blog publishing test 3
SystemVerilog-结构体(一)
【Redis】初识 Redis
Business system anti-virus
Google Borg论文
okcc呼叫中心的计费方式哪个最好
为什么建议大家尽可能选择自研公司
![[redis] set type](/img/97/0a83016e89316849c01072044f2124.png)
![[redis] list type](/img/c7/adec2aaea50d69a0aed95bfe683b9e.png)






