0

i'm trying to get the program to randomly print a item from a list, then the program to ask the user to input some information where there is true/false conditions, and then return the user to the start where they can select a new 'track'

the problem im having is that, only 'listone' is being selected and its not a random list selection thanks to all that help.

import random
questlist = ['questone', 'questtwo', 'questthree']
random.choice(questlist)


def start():
    print('Hi, welcome to the race track')
    pick = input('pick a track')
    displaytrack()


def displaytrack():
    tracks = ('track 1', 'track 2', 'track 3')
    print(tracks)



if 'questone':
    ans = input('how old are u')
    if ans == 3:
        print('Correct')
        print('Thanks for using')
        start()
    else:
            print('Incorrect')
            start()


if 'questtwo':
    ans = input('How nice are u')
    if ans == 'very':
        print('Correcterino')
        print('Thanks for using')
        start()
    else:
            print('Wrongerino')
            start()

if 'questthree':
    ans = input('How tall are u')
    if ans == 'pretty':
        print('sixfoot')
        print('Thanks for using')
        start()
    else:
            print('no feet')
            start()

2 Answers 2

1

You need to store the output of the choice and use it in your conditional expressions:

choice = random.choice(questlist)

replace

if 'questone':

with

if choice == 'questone':

and so on, otherwise, the if expressions is just checking whether the string 'questone' is None, and it will always evaluate to True.

Sign up to request clarification or add additional context in comments.

Comments

0

Use this instead of your current third line

PC_Choice = random.choice(questlist)

Then use: if PC_Choice == questone

like this:

if PC_Choice == 'questone':
    ans = input('how old are u')
    if ans == 3:
    print('Correct')
    print('Thanks for using')
    start()
else:
        print('Incorrect')
        start()

Then change the other two aswell this will make it give a random choice

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.