Solved! Thanks for helping to those who replied! I didnt’t understand the fx of None there, i was wondering why None was compared to an integer. But I did not know why line 6 has error.
smallest = None
print("Before:", smallest)
for itervar in [1, 3, 41, 12, 9, 74, 15]:
if smallest is None or itervar < smallest:
smallest = itervar
break
print("Loop:", itervar, smallest)
print("Smallest:", smallest)
You need to push the indent back of the print of loop. That is the only error. everything else is fine. If you don’t push it back, you will never get that line printed at any time. I hope you understood. You can get back to me, if you don’t understand.
I don’t think that you need to push the indent of the print back. That print is intended to show what happens inside of the loop.
@davidbrashear112 do you know what the break keyword does? It looks like this code is finding the smallest value in an array. How could a break keyword prevent this from happening?
Yes, the break should be removed and let the print loop stay as it is. It is an error in the break because it breaks the loop with the first element itself and doesn’t go through the other numbers in the list, I stand corrected.
Yes you are right @JeremyLT . No need to push the indent of the print back. The error is in the break keyword which stops it looping in the very first number it checks.