作業(判斷月份天數,判斷空,判斷季節)

2021-09-09 07:39:42 字數 1540 閱讀 9108

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

2004 2

29天2010 4

30天

"""

#_*_coding:utf-8_*_

name:01_work.py

date:1/12/19

author:

connect:[email protected]

desc:

"""year=int(input('請輸入年份:'))

mon=int(input('請輸入月份:'))

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

and ( mon == 2 ):

print('29天')

elif ( mon == 2):

print('28天')

elif ( mon == 1 ) or ( mon == 3 ) or ( mon == 5 ) or ( mon == 7 ) or ( mon == 8 ) or (mon == 10) or (mon == 12):

print('31天')

elif ( mon == 4 ) or ( mon == 6 ) or ( mon == 9 ) or ( mon == 11 ):

print('30天')

else:

print('請輸入合理的年月')

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

"""

#_*_coding:utf-8_*_

name:error.py

data:1/12/19

author:westos-sql

connect:[email protected]

desc:

"""num = str(input('please input num'))

if num == "":

print('error')

else:

print('right')

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

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

"""

#_*_coding:utf-8_*_

name:season.py

data:1/12/19

author:westos-sql

connect:[email protected]

desc:

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

if 3 <= month <= 5:

print('spring')

elif 6 <= month <= 8:

print('summer')

elif 9 <= month <= 11:

print('fall')

else:

print('winter')

```

空值判斷 型別判斷

一 判斷乙個物件是不是空 4種方法 1.object.getownpropertynames 返回值是物件中屬性名組成的陣列 如果是空陣列,即為空 eg let obj console.log object.getownpropertynames obj name age 不是空 2.轉化成字串 s...

if語句輸入月份判斷季節 C語言迴圈及條件語句

朋友以開玩笑的方式戳你傷疤,家人以對你好的名義限制你,愛你的人以不想耽誤你離你而去,唯獨陌生人安慰你。網易雲熱評 一 if語句 1 判斷正負數 include int main else val 0 顯示正數 val 0 顯示負數 val 顯示零 if val 0 else if val 0 els...

怎樣判斷判斷ResultSet是否為空

pstm conn.preparestatement select from cl articleclass where parentid order by orderid pstm.setint 1,parentid rs pstm.executequery if rs.next 使用rs.nex...