Myntra Interview Question | Simple Loop problem

Question

Use while loop to print from 1 to 50, but skip at 5,10 and 15.

in progress 0
TheDataMonk 55 years 8 Answers 1098 views Grand Master 0

Answers ( 8 )

  1. i=0
    while i < 50:
    i += 1
    if i == 5 or i == 10 or i == 15:
    continue
    print(i, end=' ')

  2. num = 0

    while num <= 50:
    num = num + 1
    if num == 5 or num == 10 or num == 15:
    continue
    print(num)

  3. i=0
    while i<51:
    if i in [5,10,15]:
    pass
    else:
    print(i)

  4. i=0
    while i<51:
    i+=1
    if not (i==5 or i==10 or i==15):
    print(i)
    continue

  5. i = 0
    while i < 50:
    i += 1
    if i == 5 or i ==10 or i ==15:
    continue
    print(i)

  6. for i in range(51):
    if i in range(5, 16, 5):
    continue
    print(i)

  7. i = 0
    while i<50:
    i = i + 1
    if i in (5,10,15):
    continue
    print(i)

Leave an answer

Browse
Browse