一、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)

  

posted @ 2019-08-29 10:42  小红帽爱吃大灰狼  阅读(2257)  评论(0编辑  收藏  举报