commit
96c60878bd
@ -0,0 +1,25 @@
|
||||
import fire
|
||||
import datetime
|
||||
|
||||
|
||||
class DateStr(object):
|
||||
|
||||
def cal_days(self, date_str1, date_str2):
|
||||
"""计算两个日期之间的天数"""
|
||||
date_str1 = str(date_str1)
|
||||
date_str2 = str(date_str2)
|
||||
d1 = datetime.datetime.strptime(date_str1, '%Y%m%d')
|
||||
d2 = datetime.datetime.strptime(date_str2, '%Y%m%d')
|
||||
delta = d1 - d2
|
||||
return delta.days
|
||||
|
||||
def days2today(self, date_str):
|
||||
"""计算某天距离今天的天数"""
|
||||
date_str = str(date_str)
|
||||
d = datetime.datetime.strptime(date_str, '%Y%m%d')
|
||||
delta = datetime.datetime.now() - d
|
||||
return delta.days
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
fire.Fire(DateStr)
|
@ -0,0 +1,30 @@
|
||||
import fire
|
||||
import random
|
||||
|
||||
|
||||
class GuessingGame:
|
||||
def __init__(self, max_number=100):
|
||||
"""初始化数据"""
|
||||
self.number = random.randint(1, max_number)
|
||||
self.max_number = max_number
|
||||
self.guesses = 0
|
||||
|
||||
def play(self):
|
||||
"""猜数游戏"""
|
||||
print(f"猜一个介于1和{self.max_number}之间的数。")
|
||||
|
||||
while True:
|
||||
guess = int(input("你的猜测是:"))
|
||||
self.guesses += 1
|
||||
|
||||
if guess < self.number:
|
||||
print("太小了,请继续猜。")
|
||||
elif guess > self.number:
|
||||
print("太大了,请继续猜。")
|
||||
else:
|
||||
print(f"恭喜你,猜对了!你一共猜了{self.guesses}次。")
|
||||
break
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
fire.Fire(GuessingGame)
|
Loading…
Reference in new issue