python第一次作業

2021-09-09 07:39:42 字數 1249 閱讀 6808

1.輸入年、月,輸出本月有多少天

# 1.輸入年月

year = int(input('year:'))

month = int(input('month:'))

# 2.判斷是那個月

if ( month == 4 or month == 6 or month == 9 or month == 11):

print('30天')

# 3.判斷是不是閏年,閏年2月29天,平年2月28天

elif ( month ==2 ):

if (year % 4 == 0 and year % 100 != 0) \

or (year % 400 == 0):

print('29天')

else:

print('28天')

else:

print('31天')

2.用if判斷輸入的值是否為空,如果為空,報錯error

a = input("請輸入:")

3.使用者輸入月份,列印該月份所屬的季節

3,4,5春季  6,7,8夏季  9,10,11秋季 12 1 2冬季

month = int(input("month:"))

if (month == 3 or month == 4 or month == 5):

print("春季")

elif (month == 6 or month == 7 or month == 8):

print("夏季")

elif (month == 9 or month == 10 or month == 11):

print("秋季")

elif (month == 12 or month == 1 or month == 2):

print("冬季")

else:

print("沒有這個月")

Python第一次作業

sheshidu float input 輸入攝氏度 huashi 9 5 sheshidu 32 print sheshidu,攝氏度等於 huashi,華氏度 banjing float input 輸入半徑 gao float input 輸入高 dimianji banjing banjin...

Python第一次作業

os.mkdir path 建立檔案 os.rename path1,path2 重新命名檔案 os.rkdir path 刪改檔案 import os path1 c mywork os.mkdir path1 path2 c mywork os.rename path1,path2 os.rmd...

python第一次作業

1 使用while迴圈輸入 1 2 3 4 5 6 8 9 101 i 1 2while i 11 3if i 7 4print i 5else 6 pass 7 i 1 2 求1 100的所有數的和i 1sum 0 for i in range 1,101 i i sum sum 0 i prin...