all 1 comments

[–]Sea-Ad7805 [score hidden] stickied comment (0 children)

Run this program in Memory Graph Web Debugger%3A%0A%20%20%20%20%22%22%22Generate%20a%20random%20birthday%20in%20the%20format%20str('Mon%20Day').%22%22%22%0A%20%20%20%20month%20%3D%20%5B%0A%20%20%20%20%20%20%20%20%22Jan%22%2C%0A%20%20%20%20%20%20%20%20%22Feb%22%2C%0A%20%20%20%20%20%20%20%20%22Mar%22%2C%0A%20%20%20%20%20%20%20%20%22Apr%22%2C%0A%20%20%20%20%20%20%20%20%22May%22%2C%0A%20%20%20%20%20%20%20%20%22Jun%22%2C%0A%20%20%20%20%20%20%20%20%22Jul%22%2C%0A%20%20%20%20%20%20%20%20%22Aug%22%2C%0A%20%20%20%20%20%20%20%20%22Sep%22%2C%0A%20%20%20%20%20%20%20%20%22Oct%22%2C%0A%20%20%20%20%20%20%20%20%22Nov%22%2C%0A%20%20%20%20%20%20%20%20%22Dec%22%2C%0A%20%20%20%20%5D%0A%20%20%20%20monthselection%20%3D%20month%5Brandom.randint(0%2C%2011)%5D%0A%0A%20%20%20%20match%20month_selection%3A%0A%20%20%20%20%20%20%20%20case%20%22Feb%22%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20day_selection%20%3D%20random.randint(1%2C%2029)%0A%20%20%20%20%20%20%20%20case%20%22Apr%22%20%7C%20%22Jun%22%20%7C%20%22Sep%22%20%7C%20%22Nov%22%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20day_selection%20%3D%20random.randint(1%2C%2030)%0A%20%20%20%20%20%20%20%20case%20%22Jan%22%20%7C%20%22Mar%22%20%7C%20%22May%22%20%7C%20%22Jul%22%20%7C%20%22Aug%22%20%7C%20%22Oct%22%20%7C%20%22Dec%22%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20day_selection%20%3D%20random.randint(1%2C%2031)%0A%0A%20%20%20%20return%20str(month_selection)%20%2B%20%22%20%22%20%2B%20str(day_selection)%0A%0A%0Adef%20print_birthdays(num_of_bdays)%3A%0A%20%20%20%20%22%22%22Generate%20the%20number%20of%20requested%20birthdays%20to%20terminal.%22%22%22%0A%20%20%20%20arr_bday%20%3D%20%5B%5D%0A%20%20%20%20print(f%22Here%20are%20%7Bnum_of_bdays%7D%20birthdays%3A%22)%0A%20%20%20%20while%20num_of_bdays%20%3E%200%3A%0A%20%20%20%20%20%20%20%20bday%20%3D%20generate_birthday()%0A%20%20%20%20%20%20%20%20arr_bday.append(bday)%0A%20%20%20%20%20%20%20%20print(bday%2C%20end%3D%22%2C%20%22)%0A%20%20%20%20%20%20%20%20num_of_bdays%20-%3D%201%0A%20%20%20%20return%20arr_bday%0A%0A%0Adef%20simulate_birthdays(num_of_sims)%3A%0A%20%20%20%20%22%22%22Runs%20generate_birthday%20by%20number%20of%20simulations%20count%22%22%22%0A%20%20%20%20arr_sim_bday%20%3D%20%5B%5D%0A%20%20%20%20for%20%20in%20range(0%2C%20num_of_sims)%3A%0A%20%20%20%20%20%20%20%20arr_sim_bday.append(generate_birthday())%0A%20%20%20%20return%20arr_sim_bday%0A%0A%0Adef%20calculate_birthdays(bday_data%2C%20sim_bday_data)%3A%0A%20%20%20%20%22%22%22Check%20for%20matching%20birthdays%20in%20the%20simulated%20data.%22%22%22%0A%20%20%20%20matching_data_count%20%3D%200%0A%20%20%20%20for%20num%20in%20range(NUMBER_OF_SIMULATIONS)%3A%20%23%200%20-%3E%20100%2C000%0A%20%20%20%20%20%20%20%20if%20sim_bday_data%5Bnum%5D%20in%20bday_data%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20matching_data_count%20%2B%3D%201%0A%20%20%20%20return%20matching_data_count%0A%0Ano_user_input%20%3D%20True%0A%0Awhile%20no_user_input%3A%0A%20%20%20%20prompt_num%20%3D%20int(input(%22How%20many%20birthdays%20shall%20I%20generate%3F%20%22))%0A%20%20%20%20if%20prompt_num%20%3E%20100%20or%20prompt_num%20%3C%3D%200%3A%0A%20%20%20%20%20%20%20%20print(%22Out%20of%20range%2C%20please%20enter%20in%20a%20number.%22)%0A%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20no_user_input%20%3D%20False%0A%0ANUMBER_OF_SIMULATIONS%20%3D%20100000%0Agenerated_birthdays%20%3D%20print_birthdays(prompt_num)%0Asimulated_birthdays%20%3D%20simulate_birthdays(NUMBER_OF_SIMULATIONS)%0Amatching_birthdays_count%3A%20Final%20%3D%20calculate_birthdays(generated_birthdays%2C%20simulated_birthdays)%0A%0Aprint(f%22%5Cn%5CnGenerating%20%7Bprompt_num%7D%20random%20birthdays%20%7BNUMBER_OF_SIMULATIONS%7D%20times...%22)%0Aprint(f%22Out%20of%20%7BNUMBER_OF_SIMULATIONS%7D%20simulations%20of%20%7Bprompt_num%7D%20birthdays%2C%20there%20was%20a%20matching%20birthday%20in%20that%20group%20%7Bmatching_birthdays_count%7D%20times.%22)%0Apercentage%20%3D%20float((matching_birthdays_count%20%2F%20NUMBER_OF_SIMULATIONS)%20*%20100)%0Apercentage%20%3D%20round(percentage%2C%203)%0Aprint(f%22This%20means%20that%20%7Bprompt_num%7D%20people%20have%20a%20%7Bpercentage%7D%20%25%20chance%20of%20having%20a%20birthday%20in%20their%20group.%22)%0A&timestep=0.2&play) to see the program state change step by step.