Python Basic Quiz #9 – For Loop

Hello Everyone! Welcome to the Short Quiz on Python For loop, Continue & Break statements.

This Quiz is made with questions from Operators. To learn about operators please check the Operators tutorial and Conditional Loops.

This Quiz contains of 5 simple questions. After completing the Quiz, immediately you will get the results displayed with correct answers.

Please feel free to provide your feedback in the comments box in bottom of the page.

Happy Programming!

Welcome to your Python Basic Quiz #9 - For Loop

1. 
What will be the output of the below code?

for x in range(1, 5):
    print("*" * x)

2. 
What will be the output of the below code?

for x in range(5):
    print(x)

3. 
What will be the output of the below code?

items = [1, -1, 3, 4, -5]

valid = 0
invalid = 0

for i in items:
    if(i > 0):
        valid = valid + 1
    else:
        invalid = invalid + 1
else:
    print("Verified")

print("Valid: " + str(valid))
print("Invalid: " + str(invalid))

4. 
What will be the output of the below code?

words = ["is", "was", "this", "that", "at"]
for item in words:
    if(len(item) > 2):
        continue
    else:
        print(item)
else:
    print("as")

5. 
What will be the output of the below code?

words = ["is", "was", "this", "that", "at"]
for item in words:
    if(len(item) > 2):
        continue
    else:
        print(item)
        break
else:
    print("as")

Our Popular Quizzes that you may like:

Leave a Reply

Your email address will not be published. Required fields are marked *