0
#TODO: QUESTION 1
    num = random.randint(1, 100)
    print(num)
    # Male or Female probabilities = 35%
    if num > 0 and num <= 18:
        femaleCheck(People)
        printPeopleList(People)
    if num > 18 and num <= 35:
        maleCheck(People)
        printPeopleList(People)
    # Wearing a T-Shirt probabilities = 15%
    if num > 35 and num <= 50:
        tShirtCheck(People)
        printPeopleList(People)
    #Eye Color probabilities 25%
    if num > 50 and num <= 63:
        eyeColorBrownCheck(People)
        printPeopleList(People)
    if num > 63 and num <= 75:
        eyeColorBlueCheck(People)
        printPeopleList(People)
    #Showing Teeth probabilities 25%
    if num > 75 and num <= 100:
        showingTeethCheck(People)
        printPeopleList(People)

Here is a small portion of the code for a guess who game that I creating. As it is currently implemented it chooses a random number from a list and asks the corresponding number to carry out a function. Once question 1 is asked I would like it to ask Question 2 out of the remaining available options. Question 3 will include the remaining 2 options, and also introduce a new function to ask. I am struggling to figure out which method would be most efficient; I know that I could just indent each question following, but that would be terribly messy and hard to read. Is there some method I could use to make the following questions asked in a simplistic manner? Potentially removing that range from random integer?

zSynonym
  • 31
  • 1
  • 1
  • 4

1 Answers1

3

If you're using 3.6 you can use random.choices with the weights keyword argument against your functions.

checkFunction = random.choices([femaleCheck, maleCheck, tShirtCheck, ...], weights=[35, 15, 25, ...])
checkFunction(People)
printPeopleList(People)

If not, check out this answer on how to implement something similar.

Community
  • 1
  • 1
joebeeson
  • 4,159
  • 1
  • 22
  • 29