0

Continue

I am trying to do the continue exercise and I am not able to add thing to my loop.

15th Mar 2021, 8:47 AM
Marcus Porter
7 Answers
0
Step1 : while: If input is negetive value, then ages<0 becomes true and enter to loop otherwise dont, loop never runs. If true then ages>=2 becomes false and ages<=2 becomes true and executes continue (but even without continue, it goes on to continue , its useless to put continue there since its last statement). And goes to step1while. And it will be repeated infinite times because ages<0 is always true. You are not changing ages value.. Hence it never comes to execute print(total) You should change value ages in every iteration.. total = 0 ages = int(input()) while ages > 0: ages = ages+1 if ages > 2: total =+100 break if ages < 2: continue print(total) This works for negetive number input and upto ages>=2 is true then adds 100 and breaks loop ...
15th Mar 2021, 10:17 AM
Jayakrishna 🇼🇳
+ 3
Since ages are not negative, the while ages < 0 will never run
15th Mar 2021, 10:16 AM
David Ashton
David Ashton - avatar
0
Can you please show us your code and the challenge question?
15th Mar 2021, 9:03 AM
Abhay
Abhay - avatar
0
total = 0 ages = int(input()) while ages == int: if ages > 2: total =+100 if ages < 2: continue print(total)
15th Mar 2021, 9:12 AM
Marcus Porter
0
Marcus Porter what are trying by ages==int ; its a error .. If 'int' is something other variable with assigned some value then , if condition true then it becomes infinite loop because you are not changing ages value for condition to becomes false. Hence it infinite loop..
15th Mar 2021, 9:33 AM
Jayakrishna 🇼🇳
0
I think I updated now so it is not looping and the code finished faster now but the total portion doesn't add regardless of the condtion. total = 0 ages = int(input()) while ages < 0: if ages >= 2: total =+100 if ages <= 2: continue print(total) if an age is under 3 it should not add 100 to the total
15th Mar 2021, 10:03 AM
Marcus Porter
0
Thanks everyone it gave me the push I needed to help me solve this problem.
15th Mar 2021, 10:56 PM
Marcus Porter