I want to display a random input option for the user and if the condition is not met it picks another random input from the list.
import random
choice = ''
clues = []
clues.append(fname:= input('What is your first name? '))
clues.append(residence:= input('Where do you live? '))
clues.append(sname:= input('What is your surname? '))
while choice != 'smores':
choice = random.choice(clues)
Doing this will just show each of the inputs then the choice is assigned a random answer from any of the inputs. What I want is for choice to pick sname as it's first option and if the user's response is not smores it will randomly pick another option from clues.
I used the walrus operator because I wasn't sure how I could save the input, using a normal variable just returns an error saying append does not take keyword arguments. The walrus operator still did what I wanted by storing and returning the values I need but if anyone has a suggestion on a different approach I'm all ears.
Aucun commentaire:
Enregistrer un commentaire