[Tutor] Problem of finding the first odd number in the list

Manprit Singh manpritsinghece at gmail.com
Thu May 6 19:45:02 EDT 2021


Dear sir ,

Let us consider  a list lst = [2, 4, 7, 9, 0], the first odd number in the
list is 7.
The code i have written for it is given below:
for i in lst:
    if i%2 != 0:
        break
print("First odd number in the list is", i)

Gives the right answer 7

The target variable i will retain the value 7 as it is the value of i when
break statement executes . Is my understanding correct ? the way i have
solved the problem is correct ?

Kindly guide.

Regards
Manprit Singh


More information about the Tutor mailing list