简体   繁体   中英

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

range = 10

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

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

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

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

You can also use FOR statement

for i in range(1,11):
    if i!=3:print i

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM