Click here to Skip to main content
15,891,657 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:


import sys
from random import randint


print("Choose: Y/N")
def main():
    user_input = str(input("y/n"))
    Choice = user_input
    if Choice == "y":
        loop()
    if Choice == "n":
        print("goodbye")
        quit()

counter = 0
trials = 0

def loop():
    global counter
    global trials
    nPeople = int(input("Enter the Number of People in the Room: "))
    myBday = randint(1,365)
    userInput = "y"
    while userInput.lower() == "y":
        for i in range (1, nPeople+1):
            if myBday == randint(1,365):
                counter += 1
                break
    trials += 1
    print(counter/trials)
    main()
    loop()
    
if __name__ == "__main__":
    loop()

I can't get the First "Main" choice to prompt a response.

What I have tried:

I have tried introducing more variables. and changing everything around.
Posted
Updated 11-Feb-18 22:49pm

1 solution

Your test at the end is wrong, __name__ is only equal to "__main__" when running interactively, or from the command line. It should be:
Python
if __name__ != "__main__":

Also the print line
Python
print("Choose: Y/N")

should be inside your main function, just before the input request, so the user knows that it is waiting for input.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900