当前位置:网站首页>温度转换 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。
边栏推荐
- Live broadcast preview | can SQL also play industrial machine learning? Mlops meetup V3 takes you to the bottom!
- 如何成为一名高级数字 IC 设计工程师(3-5)工具篇:SpyGlass 技术
- How to become a senior digital IC Design Engineer (5-1) theory: clock technology, reset Technology
- [redis] set type
- 大三下期末考試
- Com3529 test analysis
- 如何成为一名高级数字 IC 设计工程师(4-2)脚本篇:Verilog HDL 代码实现的文件读写操作
- Exclusive analysis | real situation of software test about resume and interview
- [learn FPGA programming from scratch -50]: Vision - how are chips made? The thirteen steps of chip manufacturing.
- 大三下期末考试
猜你喜欢

SAP ui5 beginner tutorial 22 - development and use of filter

Introduction to super dongle scheme

Redis data migration (III)

CTFHub-Web-密码口令-默认口令
![[机缘参悟-33]:眼见不一定为实,大多数时候“眼见为虚”](/img/60/703a5bc3038d28bcf812415032f240.jpg)
[机缘参悟-33]:眼见不一定为实,大多数时候“眼见为虚”

【Redis】Set类型

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

直播预告|SQL也能玩转工业级机器学习?MLOps meetup V3带你一探究竟!

To apply for a test engineer after years, the resume with high scores should be written like this

Oculusrifts and unity UI interaction (1) - Overview
随机推荐
I'd like to ask you, where can I open an account in Zhongshan? Is it safe to open an account online?
Scala Foundation (3): Operators and Process Control
TiFlash 面向编译器的自动向量化加速
基于 FPGA 的 RISC CPU 设计(4)关于项目的 36 个问题及其答案
Fundamentals of scala (3): operators and process control
Wechat campaign auto like
How to manage device authorization
Use code binding DataGridView control to display tables in program interface
Adding, deleting, checking and modifying stack - dynamic memory
Qt基础教程:数据类型与容器
Eliminate the hover effect when the button is disabled
QT basics tutorial: data types and containers
Finally got the byte offer. The 25-year-old inexperienced experience in software testing is written to you who are still confused
Server antivirus
Blog publishing test 2
Zhongyi technology resumed the review status of the gem IPO, and xuxiaofei no longer acted as a practicing lawyer
Pyinstaller打包pikepdf失败的问题排查
[redis] sortedset type
【学习笔记】子集和问题
东方财富股票开户是会有什么风险吗?东方财富开户安全吗