Home > Back-end >  Which line has an error in this for loop?
Which line has an error in this for loop?

Time:01-09

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?

CodePudding user response:

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.

  •  Tags:  
  • Related