diff --git a/Day31-35/code/dayofyear.py b/Day31-35/code/dayofyear.py new file mode 100644 index 0000000..2894c9f --- /dev/null +++ b/Day31-35/code/dayofyear.py @@ -0,0 +1,21 @@ +import sys +import mycal + + +def main(): + if len(sys.argv) != 4: + print('Not enough arguments') + return + year = int(sys.argv[1]) + month = int(sys.argv[2]) + day = int(sys.argv[3]) + total = 0 + for m in range(1, month): + total += mycal.get_days(year, m) + total += day + print(f'{year}年{month}月{day}日是{year}年的第{total}天') + + +if __name__ == '__main__': + main() + diff --git a/Day31-35/code/guess.py b/Day31-35/code/guess.py new file mode 100644 index 0000000..44950f4 --- /dev/null +++ b/Day31-35/code/guess.py @@ -0,0 +1,20 @@ +#!/usr/bin/python3 +# coding: utf-8 +from random import randint + + +def main(): + answer = randint(1, 100) + while True: + number = int(input('请输入: ')) + if number < answer: + print('大一点') + elif number > answer: + print('小一点') + else: + print('恭喜你猜对了!') + break + + +if __name__ == '__main__': + main() diff --git a/Day31-35/code/josephu.py b/Day31-35/code/josephu.py new file mode 100644 index 0000000..8806299 --- /dev/null +++ b/Day31-35/code/josephu.py @@ -0,0 +1,22 @@ +def main(): + persons = [True] * 30 + counter = 0 + index = 0 + number = 0 + while counter < 15: + if persons[index]: + number += 1 + if number == 9: + persons[index] = False + number = 0 + counter += 1 + index += 1 + index %= len(persons) + for person in persons: + print('基' if person else '非', end='') + print() + + +if __name__ == '__main__': + main() + diff --git a/Day31-35/code/mycal.py b/Day31-35/code/mycal.py new file mode 100644 index 0000000..5738e87 --- /dev/null +++ b/Day31-35/code/mycal.py @@ -0,0 +1,46 @@ +#!/usr/bin/python3 +from datetime import datetime +import sys + + +def is_leap(year): + return year % 4 == 0 and year % 100 != 0 or year % 400 == 0 + + +def get_days(year, month): + days = [[31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31], + [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]] + return days[is_leap(year)][month - 1] + + +def main(): + if len(sys.argv) > 1: + month = int(sys.argv[1]) + year = int(sys.argv[2]) + else: + current_date = datetime.now() + year = current_date.year + month = current_date.month + year2 = year if month >= 3 else year - 1 + c = year2 // 100 + y = year2 % 100 + m = month if month >= 3 else month + 12 + w = y + y // 4 + c // 4 - 2 * c + 26 * (m + 1) // 10 + w %= 7 + months = ['January', 'February', 'March', 'April', 'May', 'June', + 'July', 'August', 'September', 'October', 'November', 'December'] + print(f'{months[month - 1]} {year}'.center(20)) + print('Su Mo Tu We Th Fr Sa') + print(' ' * 3 * w, end='') + total_days = get_days(year, month) + for day in range(1, total_days + 1): + print(f'{day}'.rjust(2), end=' ') + w += 1 + if w == 7: + print() + w = 0 + print() + + +if __name__ == '__main__': + main()