Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Which line has an error in this for loop?

This question is from a python course on freeCodeCamp.com

smallest = None
print("Before:", smallest)
for itervar in [3, 41, 12, 9, 74, 15]:
    if smallest is None or itervar < smallest:
        smallest = itervar
        break
    print("Loop:", itervar, smallest)
print("Smallest:", smallest)

There is a mistake in one of these lines. I thought it’s the fourth line because the variable ‘smallest’ is already written as None in the first line but it’s not the right answer. Also, what type of value is None and what is it for?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You don’t need a break on 5th line. It interrupts the loop which is not needed there.

Without it everything works okay.

Also, what type of value is None and what is it for?

The None keyword is used to define a null value, or no value at all.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading