Merge branch 'master' of github.com:jackfrued/Python-100-Days

pull/19/head
jackfrued 2018-07-23 00:33:20 +08:00
commit 02918d50f2
4 changed files with 109 additions and 0 deletions

View File

@ -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()

View File

@ -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()

View File

@ -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()

View File

@ -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()