Q:

Write a Python program to remove and print every third number from a list of numbers until the list becomes empty

belongs to collection: python basic programs with examples

0

Write a Python program to remove and print every third number from a list of numbers until the list becomes empty

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

I have used python 3.7 compiler for debugging purpose.

def remove_nums(int_list):
  #list starts with 0 index
  position = 3 - 1 
  idx = 0
  len_list = (len(int_list))
  while len_list>0:
    idx = (position+idx)%len_list
    print(int_list.pop(idx))
    len_list -= 1
nums = [10,20,30,40,50,60]
remove_nums(nums)

Result:

30

60

40

20

50

10

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

python basic programs with examples

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Write a Python program to create the combinations ... >>
<< Write a Python program to convert true to 1 and fa...