1.華氏溫度轉換爲攝氏溫度 轉換公式爲:C=(F - 32) \1.8
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)
說明:上面的print函數中輸出的字符串使用了佔位符語法
3.輸入年份判斷是不是閏年
能被4整除且不能被100整除或者能被400整除的年份是閏年
輸入年份 如果是閏年輸出True 否則輸出False
year = int(input('請輸入年份: '))
# 如果代碼太長寫成一行不便於閱讀 可以使用\對代碼進行折行
is_leap = (year % 4 == 0 and year % 100 != 0) or \
year % 400 == 0
print(is_leap)