my code:
question_prompts = [
"What color are apples?]\n(a) Red/Green \n(b) Yellow \n(c) Purple\n\n",
]
print(question_prompts)
\n in this array [] didn't work. It cannot be down a new line. Hope to get your help
my code:
question_prompts = [
"What color are apples?]\n(a) Red/Green \n(b) Yellow \n(c) Purple\n\n",
]
print(question_prompts)
\n in this array [] didn't work. It cannot be down a new line. Hope to get your help
That's because you are printing the list and not the string whose inside the list, try this:
question_prompts = [
"What color are apples?]\n(a) Red/Green \n(b) Yellow \n(c) Purple\n\n",
]
for prompt in question_prompts:
print(prompt)
The issue is you are printing the whole of question_prompts which just shows you what is in the whole of that array without getting a new line.
You need to specifically print the first element:
>>> print(question_prompts[0])
What color are apples?]
(a) Red/Green
(b) Yellow
(c) Purple
To print all the elements:
for prompt in question_prompts:
print(prompt)
You will need to print the items separately, as follows:
question_prompts = ["What color are apples?", "(a) Red / Green", "(b) Yellow", "(c) Purple"]
for item in question_prompts:
print(item)
Since the string is inside a list, it does not print properly..
You can use
for q in question_prompts:
print(q)
and you should see the newlines
It would be easy to work with if you use a dictionary for your options instead.
question = "What color are apples?"
options = {'a': 'Red/Green', 'b': 'Yellow', 'c': 'Purple'}
print(question)
for option in "abcd":
print(f'({option}) {options[option]}')