I am new to python and trying to learn through small projects:
I am trying to write a code where if suppose you are in a large-lecture class with n other students.Determine how large n must be such that the probability that someone has the same birthday as you is greater than 50%? Note: Forgetting about leap years and so assuming 365 days in a year, the probability that no one has the same birthday as you is (364/365)**n
My code for this is:
n=probability
probability = 0
while n==0.50*n:
print("With n students, the
probability
is greater than
50% that someone has the same
birthday
as you.")
Where am I going wrong?How could I implement an ifstatement?The output I am looking for is:
With 253 students, the probability is greater than 50% that someone has the same birthday as you.
Aucun commentaire:
Enregistrer un commentaire