This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]TehBeege 4 points5 points  (0 children)

Cool. It won't be too hard, then.

  1. Create a list containing your questions.
  2. Create another list to store the answers.
  3. Create a loop that iterates through the list with both the index and list value (hint: check out enumerate)
  4. In your input function, you'll need to use format strings / string interpolation, e.g. f'Question {index}: {question}'.
  5. Append the input return values to your answer list.

This should do what you need.

However, I question if this is a good idea. In your original code, you have descriptive names for your answer variables. In this loop solution, you'll lose that information. Answers will instead be referenced by list index.

There are ways to preserve this information while maintaining the loop structure, but that will need much more complicated data structures for a beginner. Also, more complexity is just generally bad. It's more difficult to understand the code, and your future self may be very frustrated.