Hallo coders!
De volgende code:
Regel 24
Bij maandlijst = DaysInMonth(year,month)
Zit er een verschil tussen maandlijst en DaysInMonth(year,month) ?
Want als ik bij de vergelijking:
in plaats van maandlijst, DaysInMonth(year,month) neerzet, komt er een type error:
TypeError: '>' not supported between instances of 'int' and 'list'
Hoe komt het dat maandlijst wel werkt in een vergelijking ( or < > ) en DaysInMonth(year,month) niet?
De volgende code:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
| def IsYearLeap(year):
if year % 4 != 0:
return False
elif year % 100 != 0:
return True
elif year % 400 != 0:
return False
else:
return True
def DaysInMonth(year,month):
normalmonthslist = [31,28,31,30,31,30,31,31,30,31,30,31]
leapmonthslist = [31,29,31,30,31,30,31,31,30,31,30,31]
if IsYearLeap(year) == True:
return leapmonthslist[:month]
else:
return normalmonthslist[:month]
#print(DaysInMonth(2000,5))
def DayOfYear(year,month,day):
maandlijst = DaysInMonth(year,month)
if month <1 or month > 12:
return None
if day < 1 or day > maandlijst[-1]:
return None
del maandlijst[-1]
total = 0
for i in maandlijst:
total+=i
return total + day
print(DayOfYear(2000,12,31))
print(DayOfYear(2015,1,25))
print(DayOfYear(2015,12,31)) |
Regel 24
Bij maandlijst = DaysInMonth(year,month)
Zit er een verschil tussen maandlijst en DaysInMonth(year,month) ?
Want als ik bij de vergelijking:
code:
1
2
3
4
| if month <1 or month > 12:
return None
if day < 1 or day > maandlijst[-1]:
return None |
in plaats van maandlijst, DaysInMonth(year,month) neerzet, komt er een type error:
TypeError: '>' not supported between instances of 'int' and 'list'
Hoe komt het dat maandlijst wel werkt in een vergelijking ( or < > ) en DaysInMonth(year,month) niet?