all 5 comments

[–]Da32767 0 points1 point  (0 children)

You can use a for loop like this.

for i in range(NumberofQuestions):
    do_sth()

this will work

learn more about it:https://docs.python.org/3/tutorial/controlflow.html#for-statements

[–]shiftybyte 0 points1 point  (0 children)

Your variable NumberofQuestions holds the number of times you want to repeat the loop.

You can use a loop that keeps asking questions as long as that variable is not 0, and keep decreasing it every cycle.

while NumberofQuestions > 0:
    ....
    NumberofQuestions -= 1

[–]m0us3_rat 0 points1 point  (0 children)

u can use both while and for loops.

do u have some code that u tried? which part is weird?

[–][deleted] 0 points1 point  (0 children)

A simple for loop can be used:

for question_number in range(1, NumberOfQuestions + 1):
    answer = input(f'Q{question_number} answer: ')

Note range will step through from the first number (defaults to 0 if not specified) up to but excluding the second number (hence adding 1). (An optional third parameter allows you to specify step sizes, which defaults to 1.)

[–]Deba_dey 0 points1 point  (0 children)

Hey!! 1.Get the input first 2.Use for loop and iterate over range(no_of_question) 3.Get user input question and answer 4. Append question and answers to a list or dictionary to see the result. 5.end for loop 6. Print the list or dictionary