Skip to content

Commit 02918d5

Browse files
committed
Merge branch 'master' of github.com:jackfrued/Python-100-Days
2 parents d8046d4 + 004d9d4 commit 02918d5

File tree

4 files changed

+109
-0
lines changed

4 files changed

+109
-0
lines changed

Day31-35/code/dayofyear.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import sys
2+
import mycal
3+
4+
5+
def main():
6+
if len(sys.argv) != 4:
7+
print('Not enough arguments')
8+
return
9+
year = int(sys.argv[1])
10+
month = int(sys.argv[2])
11+
day = int(sys.argv[3])
12+
total = 0
13+
for m in range(1, month):
14+
total += mycal.get_days(year, m)
15+
total += day
16+
print(f'{year}{month}{day}日是{year}年的第{total}天')
17+
18+
19+
if __name__ == '__main__':
20+
main()
21+

Day31-35/code/guess.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/python3
2+
# coding: utf-8
3+
from random import randint
4+
5+
6+
def main():
7+
answer = randint(1, 100)
8+
while True:
9+
number = int(input('请输入: '))
10+
if number < answer:
11+
print('大一点')
12+
elif number > answer:
13+
print('小一点')
14+
else:
15+
print('恭喜你猜对了!')
16+
break
17+
18+
19+
if __name__ == '__main__':
20+
main()

Day31-35/code/josephu.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
def main():
2+
persons = [True] * 30
3+
counter = 0
4+
index = 0
5+
number = 0
6+
while counter < 15:
7+
if persons[index]:
8+
number += 1
9+
if number == 9:
10+
persons[index] = False
11+
number = 0
12+
counter += 1
13+
index += 1
14+
index %= len(persons)
15+
for person in persons:
16+
print('基' if person else '非', end='')
17+
print()
18+
19+
20+
if __name__ == '__main__':
21+
main()
22+

Day31-35/code/mycal.py

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/python3
2+
from datetime import datetime
3+
import sys
4+
5+
6+
def is_leap(year):
7+
return year % 4 == 0 and year % 100 != 0 or year % 400 == 0
8+
9+
10+
def get_days(year, month):
11+
days = [[31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31],
12+
[31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]]
13+
return days[is_leap(year)][month - 1]
14+
15+
16+
def main():
17+
if len(sys.argv) > 1:
18+
month = int(sys.argv[1])
19+
year = int(sys.argv[2])
20+
else:
21+
current_date = datetime.now()
22+
year = current_date.year
23+
month = current_date.month
24+
year2 = year if month >= 3 else year - 1
25+
c = year2 // 100
26+
y = year2 % 100
27+
m = month if month >= 3 else month + 12
28+
w = y + y // 4 + c // 4 - 2 * c + 26 * (m + 1) // 10
29+
w %= 7
30+
months = ['January', 'February', 'March', 'April', 'May', 'June',
31+
'July', 'August', 'September', 'October', 'November', 'December']
32+
print(f'{months[month - 1]} {year}'.center(20))
33+
print('Su Mo Tu We Th Fr Sa')
34+
print(' ' * 3 * w, end='')
35+
total_days = get_days(year, month)
36+
for day in range(1, total_days + 1):
37+
print(f'{day}'.rjust(2), end=' ')
38+
w += 1
39+
if w == 7:
40+
print()
41+
w = 0
42+
print()
43+
44+
45+
if __name__ == '__main__':
46+
main()

0 commit comments

Comments
 (0)