Guys I wrote a program that creates 23 random numbers(birthdays)
and the counts how many duplicates are there.
How come sometimes when I run this it returns "None"?
Here is the code:
import random
#Checks for duplicates.
def has_duplicates(userstring):
userlist = list(userstring)
list_len = len(userlist)
len_no_duplicates = len(set(userlist))
if list_len != len_no_duplicates:
return True
return False
def bdays_23():
birthdays = []
while len(birthdays) <= 23:
birthdays.append(random.randint(1, 365))
return birthdays
def in_common():
if has_duplicates(bdays_23()) == True:
return len(bdays_23()) - len(set(bdays_23()))
def main():
"""
main function
"""
print in_common()
return 0
if __name__ == "__main__":
main()