I'm creating a text game to learn the basics of python, it is basically a short quiz game to determine your game character.
I wanted the question to print as if they were being typed, like this:
In=list("What is your name? ")
for x in In:
print(x, end='')
stdout.flush()
time.sleep(0.1)
print("
")
Then I wondered if I could make a function that could print the correct question from a variable containing a list of questions based on the argument given to the function. If the argument given is "1" it would print question 1 and so on... I keep having to come back to functions, I find them one of the most confusing.
I tried the below code, thinking perhaps lists in lists, but then it prints both questions. I need a way to identify just one 'item' from the variable.
import time
from sys import stdout
def ask_question():
for list in list_questions:
for item in list:
for x in item:
print(x, end='')
stdout.flush()
time.sleep(0.1)
list_questions = [["What is your name?"], ["What is your age? "]]
Questions I am wondering (and will look into after sleeping on it, but thought I would put here anyway):
Is it possible to use something other than a list here? Strings are iterable, would they be in some way easier to use for this?
How do you identify a list within a list? Is the below format for strings?
print(list_questions[0,1])
Could a dictionary be used?
Is there a completely different, better way of doing this whole thing?
If anyone has an abundance of free time and wat to look over the whole text game (there are many, many problems to be found) feel free:
https://github.com/hyperblue1356/Radiant_text_game/blob/main/code
question from:
https://stackoverflow.com/questions/65904441/creating-a-function-to-print-a-different-question-based-on-the-argument-given 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…