当前位置:网站首页>温度转换 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。
边栏推荐
- A full screen gesture adaptation scheme
- Is the ETF fund reliable and safe
- Use kubernetes resource lock to complete your own ha application
- 110. 简易聊天室13:聊天室服务端
- [high concurrency, high performance and high availability of massive data MySQL practice-10] - Implementation of mvcc in InnoDB
- Qt基础教程:数据类型与容器
- Scala 基礎 (三):運算符和流程控制
- [understanding of opportunity -33]: seeing is not necessarily true. Most of the time, "seeing is false"
- [C language] Fibonacci sequence and frog jumping steps (the most detailed elementary frog jumping steps)
- 我把整个研发中台拆分过程的一些心得总结
猜你喜欢
![[redis] get to know redis for the first time](/img/02/3c6a7f6ea8c563386a4cd458024728.png)
[redis] get to know redis for the first time

如何成为一名高级数字 IC 设计工程师(4-5)脚本篇:Shell 脚本实现的文件比较操作

如何成为一名高级数字 IC 设计工程师(4-2)脚本篇:Verilog HDL 代码实现的文件读写操作

Koa 快速入門

基于 RISC-V SoC 的可配置 FFT 系统设计(1)引言

Boost the digital economy and face the future office | the launch of the new version of spreadjsv15.0 is about to begin

如何成为一名高级数字 IC 设计工程师(4-3)脚本篇:C 语言实现的文件读写操作

【Redis】List类型

CTFHub-Web-密码口令-默认口令

Redis data migration (III)
随机推荐
数字 IC 设计、FPGA 设计秋招笔试题目、答案、解析(2)2021 华为海思(上)
Pyinstaller打包pikepdf失败的问题排查
Use code binding DataGridView control to display tables in program interface
[learn FPGA programming from scratch -50]: Vision - how are chips made? The thirteen steps of chip manufacturing.
Live broadcast preview | can SQL also play industrial machine learning? Mlops meetup V3 takes you to the bottom!
【Redis】数据介绍 & 通用命令 & String类型
[high concurrency, high performance and high availability of massive data MySQL practice-10] - Implementation of mvcc in InnoDB
[C language] Fibonacci sequence and frog jumping steps (the most detailed elementary frog jumping steps)
How to become a senior digital IC Design Engineer (5-1) theory: clock technology, reset Technology
SAP ui5 beginner tutorial 22 - development and use of filter
如何成为一名高级数字 IC 设计工程师(4-2)脚本篇:Verilog HDL 代码实现的文件读写操作
okcc呼叫中心的计费方式哪个最好
Which brokerage is safer and more convenient to open an account for compass mobile stock?
RISC CPU design based on FPGA (4) 36 questions about the project and their answers
如何成为一名高级数字 IC 设计工程师(3-5)工具篇:SpyGlass 技术
OpenResty 使用介绍
What is stock online account opening? Is it safe to open an account online?
利用kubernetes資源鎖完成自己的HA應用
直播预告|SQL也能玩转工业级机器学习?MLOps meetup V3带你一探究竟!
B1009 irony