Python element "list[ ]" with variable length?

Good morning,

I'm currently coding a small project in Python. The idea is to first ask what possible answers there should be for a specific question. Then, these possible answers should be available to another person (using the same terminal) for selection.

So I would like a list to be created with the individual answer options, which will vary in length depending on the number of answer options, so that this list can be used later.

How do I do that? I've only recently started using Python, so I'm not very familiar with it yet…

Thanks in advance to everyone who writes an answer!

(2 votes)
Loading...

Similar Posts

Subscribe
Notify of
3 Answers
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
GuteAntwort2021
1 year ago

Hello.

The meaning of a list is that one wants to have a variable-length container.

Declaration:

my_list = []

Add item:

my_list.append("Antwortmöglichkeit 1")

Select random element:

import random
print(random.choice(my_list))

Delete item:

my_list.remove("Antwortmöglichkeit 1")

Otherwise, your text is not clear. Would you like to enter a question with the possibility of answering it and then someone who is asked the question and will be presented with the answers? Or how exactly was that supposed?

KarlRanseierIII
1 year ago

Lists are inherently variable in length. You can add, remove elements at any time, …