菜鸟教程 -- 学的不仅是技术,更是梦想!

Python 3 教程
Python3 教程 Python3 简介 Python3 环境搭建 Python3 VScode Python3 基础语法 Python3 基本数据类型 Python3 数据类型转换 Python3 解释器 Python3 注释 Python3 运算符 Python3 数字(Number) Python3 字符串 Python3 列表 Python3 元组 Python3 字典 Python3 集合 Python3 条件控制 Python3 循环语句 Python3 编程第一步 Python3 推导式 Python3 迭代器与生成器 Python3 with Python3 函数 Python3 lambda Python3 装饰器 Python3 数据结构 Python3 模块 Python __name__ Python3 输入和输出 Python3 File Python3 OS Python3 错误和异常 Python3 面向对象 Python3 命名空间/作用域 Python 虚拟环境的创建 Python 类型注解 Python3 标准库概览 Python3 实例 Python 测验

Python3 高级教程

Python3 正则表达式 Python3 CGI编程 Python3 MySQL(mysql-connector) Python3 MySQL(PyMySQL) Python3 网络编程 Python3 SMTP发送邮件 Python3 多线程 Python3 XML 解析 Python3 JSON Python3 日期和时间 Python3 内置函数 Python3 MongoDB Python3 urllib Python uWSGI 安装配置 Python3 pip Python3 operator Python math Python requests Python random Python OpenAI Python 有用的资源 Python AI 绘画 Python statistics Python hashlib Python 量化 Python pyecharts Python selenium 库 Python 爬虫 Python Scrapy 库 Python Markdown Python sys 模块 Python Pickle 模块 Python subprocess 模块 Python queue 模块 Python StringIO 模块 Python logging 模块 Python datetime 模块 Python re 模块 Python csv 模块 Python threading 模块 Python asyncio 模块 Python PyQt Python for 循环 Python while 循环
(追記) (追記ここまで)

Python 摄氏温度转华氏温度

Document 对象参考手册 Python3 实例

以下实例演示了如何将摄氏温度转华氏温度:

实例

# -*- coding: UTF-8 -*-# Filename : test.py# author by : www.runoob.com# 用户输入摄氏温度# 接收用户输入celsius = float(input('输入摄氏温度: '))# 计算华氏温度fahrenheit = (celsius * 1.8) + 32print('%0.1f 摄氏温度转为华氏温度为 %0.1f ' %(celsius,fahrenheit))

执行以上代码输出结果为:

输入摄氏温度: 38
38.0 摄氏温度转为华氏温度为 100.4 

以上实例中,摄氏温度转华氏温度的公式为 celsius * 1.8 = fahrenheit - 32。所以得到以下式子:

celsius = (fahrenheit - 32) / 1.8

Document 对象参考手册 Python3 实例

AI 思考中...

2 篇笔记 写笔记

  1. #0

    萝卜国王

    142***[email protected]

    90

    摄氏度和华氏度相互转换

    #!/usr/bin/python
    # -*- coding:utf-8 -*-
    a = int(input('摄氏度转换为华氏温度请按1\n华氏温度转化为摄氏度请按2\n'))
    while a != 1 and a != 2:
     a = int(input('你选择不正确,请重新输入。\n摄氏度转换为华氏温度请按1\n华氏温度转换为摄氏度请按2\n'))
    if a == 1:
     celsius = float(input('输入摄氏度:'))
     fahrenheit = (celsius*1.8)+32 #计算华氏温度
     print('%.1f摄氏度转为华氏温度为%.1f' %(celsius,fahrenheit))
    else:
     fahrenheit = float(input('输入华氏度:'))
     celsius = (fahrenheit - 32)/1.8 #计算摄氏度
     print('%.1f华氏度转为摄氏度为%.1f' %(fahrenheit,celsius))

    萝卜国王

    142***[email protected]

    9年前 (2018年01月19日)
  2. #0

    周伯通

    136

    参考方法:

    a = input("请输入带有符号的温度值: ")
    if a[-1] in ['F','f']:
     C = (eval(a[0:-1]) - 32)/1.8
     print("转换后的温度是{:.1f}C".format(C))
    elif a[-1] in ['C','c']:
     F = 1.8*eval(a[0:-1]) + 32
     print("转换后的温度是{:.1f}F".format(F))
    else:
     print("输入格式错误")

    测试结果:

    请输入带有符号的温度值: 38C
    转换后的温度是100.4F

    周伯通

    8年前 (2018年06月11日)

点我分享笔记

  • 昵称 (必填)
  • 邮箱 (必填)
  • 引用地址

AltStyle によって変換されたページ (->オリジナル) /