一、python入门练习题,,题目:练习1:华氏温


题目:

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

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

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

答案:

练习1:

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

 

练习2:

"""输入半径计算圆的周长和面积"""
import mathradius = float(input(‘请输入圆的半径: ‘))perimeter = 2 * math.pi * radiusarea = math.pi * radius * radiusprint(‘周长: %.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)

  

一、python入门练习题

评论关闭