Home > database >  How can I print 1 to 10, except 3 using while loop? I want to write that in Python code
How can I print 1 to 10, except 3 using while loop? I want to write that in Python code

Time:11-01

range = 10

i=1 while i < range: print(i) i = 1

Is there any way use 'continue statement' and make it happen?

CodePudding user response:

Simplest method is this:

rng= 11
i = 1
while i < rng:
    print(i)
    i =1
    if i ==3:
        i =1

so when i = 3, it skips that i - I don't think you would need anything more complex than this

output is: 1 2 4 5 6 7 8 9 10

CodePudding user response:

while i < 10 :
   if i != 3 :
       print(i)
   i =1
  • Related