Compare commits
3 Commits
28913baa5e
...
701a403eee
Author | SHA1 | Date |
---|---|---|
|
701a403eee | |
|
2a372c5d6f | |
|
a8e95bba21 |
|
@ -0,0 +1,79 @@
|
||||||
|
import random
|
||||||
|
import datetime
|
||||||
|
|
||||||
|
motchs = ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
|
||||||
|
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec')
|
||||||
|
|
||||||
|
def getBarthday(inp):
|
||||||
|
date = datetime.date(2000, 1, 1)
|
||||||
|
dates = []
|
||||||
|
for i in range(1, int(inp) + 1):
|
||||||
|
rand_day = datetime.timedelta(random.randint(1, 364))
|
||||||
|
rand_date = date + rand_day
|
||||||
|
dates.append(rand_date)
|
||||||
|
return dates
|
||||||
|
|
||||||
|
def sameDate(dates):
|
||||||
|
if len(dates) == len(set(dates)):
|
||||||
|
return None
|
||||||
|
for a, barthdeyA in enumerate(dates):
|
||||||
|
for b, barthdeyB in enumerate(dates[a + 1:]):
|
||||||
|
if barthdeyA == barthdeyB:
|
||||||
|
return barthdeyA
|
||||||
|
|
||||||
|
def getMonth(dates):
|
||||||
|
for i, date in enumerate(dates):
|
||||||
|
if i != 0:
|
||||||
|
print(', ', end='')
|
||||||
|
motch = motchs[date.month - 1]
|
||||||
|
print(f"{motch} {date.day}", end='')
|
||||||
|
|
||||||
|
def sameMonth(dates):
|
||||||
|
date = sameDate(dates)
|
||||||
|
if date != None:
|
||||||
|
same_date = motchs[date.month - 1]
|
||||||
|
print(f"\nSame a {same_date} {date.day}")
|
||||||
|
else:
|
||||||
|
print("Nohing same")
|
||||||
|
|
||||||
|
def simualtion(inp):
|
||||||
|
digit = 0
|
||||||
|
for i in range(100_000):
|
||||||
|
dates = getBarthday(inp)
|
||||||
|
sam_date = sameDate(dates)
|
||||||
|
if i % 10_000 == 0 and i != 0:
|
||||||
|
print(f"Simulations {i}")
|
||||||
|
if sam_date != None:
|
||||||
|
digit += 1
|
||||||
|
chanse = round((digit/100_000) * 100, 2)
|
||||||
|
print(f"Same = {digit}")
|
||||||
|
print(f"Chanse = {chanse}")
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
while True:
|
||||||
|
inp = ''
|
||||||
|
while not inp.isdecimal() or int(inp) > 100:
|
||||||
|
print("Enter number no more than 100")
|
||||||
|
inp = input("> ")
|
||||||
|
dates = getBarthday(inp)
|
||||||
|
getMonth(dates)
|
||||||
|
sameMonth(dates)
|
||||||
|
simualtion(inp)
|
||||||
|
print("You want play again?")
|
||||||
|
if not input("(yes/no)> ").startswith('y'):
|
||||||
|
print("Thanks for playing")
|
||||||
|
break
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue