Can anyone figure out why my loop counter isn't working during my while statement (Iterating) . Loop should equal nine when running . I Also should see skipping - 5 when running because it is less than 0
values = [ 3, 53, 19, -5, 60, 41, "test", 5, 2, 9, 22]
#create a loop using a for or while
for i in values:
# Use one or more if-elif-else conditional statements within the loop
if i == 9:
# Use a break statement
break
elif isinstance(i, str):
# Use a continue statement
continue
else:
print(i)
while loop example
total = 0
loop = 0
while total < 200:
if isinstance(values[loop], str):
loop +-1
continue
elif values[loop] > 0:
total += values[loop]
else:
print(f'skipping {values[loop]}')
if loop == len(values)-1:
break
loop += 1
print(f'sum: {total}, loop: {loop}')
Terminal After Running Code
3
53
19
-5
60
41
5
2
sum: 201, loop: 0
Aucun commentaire:
Enregistrer un commentaire