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


Introduction

Write a Python program to remove and print every third number from a list of numbers until the list becomes empty. I have used python 3.7 compiler for debugging purpose.


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

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

Result

python language techstudy.org

     





Related Topics




Popular Posts