Compare commits

...

3 Commits

Author SHA1 Message Date
User 701a403eee I wrote it from memory 2025-05-04 14:58:34 +03:00
User 2a372c5d6f Packing code into functions 2025-05-04 13:56:24 +03:00
User a8e95bba21 First code 2025-05-04 11:38:42 +03:00
1 changed files with 79 additions and 0 deletions

View File

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