zoukankan      html  css  js  c++  java
  • 一、python入门练习题

    题目:

    练习1:华氏温度转摄氏温度。

    练习2:输入圆的半径计算计算周长和面积。

    练习3:输入年份判断是不是闰年。

    答案:

    练习1:

    """
    将华氏温度转换为摄氏温度
    F = 1.8C + 32
    """
    
    f = float(input('请输入华氏温度: '))
    c = (f - 32) / 1.8
    print('%.1f华氏度 = %.1f摄氏度' % (f, c))
    

     

    练习2:

    """
    输入半径计算圆的周长和面积
    """
    import math radius = float(input('请输入圆的半径: ')) perimeter = 2 * math.pi * radius area = math.pi * radius * radius print('周长: %.2f' % perimeter) print('面积: %.2f' % area)

    练习3:

    """
    输入年份 如果是闰年输出True 否则输出False
    """
    
    year = int(input('请输入年份: '))
    # 如果代码太长写成一行不便于阅读 可以使用或()折行
    is_leap = (year % 4 == 0 and year % 100 != 0 or
               year % 400 == 0)
    print(is_leap)
    

      

  • 相关阅读:
    spring mvc 总结
    linux安装tomcat及优化
    mysql支持emoji表情
    面试问题
    linux安装jdk mysql
    webstorm 介绍
    spring 总结
    UML工具
    js bom dom
    awt多线程聊天
  • 原文地址:https://www.cnblogs.com/jieperhaps/p/11428318.html
Copyright © 2011-2022 走看看