Question: Q1: Solve the above question using a for loop. Write two programs, one using continue statement and one without using continue. In [ ]: nums


![]: nums 1 ### using a for loop solution 1 2 [2,](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f2f5309afba_51266f2f5301ede9.jpg)
Q1: Solve the above question using a for loop. Write two programs, one using continue statement and one without using continue. In [ ]: nums 1 ### using a for loop solution 1 2 [2, 5, 0, 4, 3, 0, 10, 0, 8, 8, 20] 3 4. 5 6 7 8 print('done') In [ ]: i ### using a for loop - solution 2 2 3 4 5 6 7 8 print('done') Part 2 Conditionals, for Loops and while Loops Review the followng solved example before proceeding to the rest of the lab questions. QO: Solved Example: Given the list nums = [2,5, 0, 4, 3, 0, 10, 0, 8, 8, 20], Write a while loop that prints all non-zero numbers from a list of numbers. The numbers should be printed in the same relative order they appear in the list. In [16]: i ### using a while loop solution 1 2 nums [2, 5, 0, 4, 3, 0, 10, 0, 8, 8, 20] 3 4 nums.reverse(). 5 print(nums) 6 while nums: # while list nums is not empty 7 r = nums.pop(). 8 if r == 0: 9 continue 10 print(r) 11 12 13 print('done') 14 [20, 8, 8, 0, 10, 0, 3, 4, 0, 5, 2] 2 4 3 10 8 8 20 done In [17] : i ### using a while loop solution 2 2 3 nums [2, 5, 0, 4, 3, 0, 10, 0, 8, 8, 20] 4 5 print (nums) 6 while nums: # while list nums is not empty 7 r = nums.pop(). 8 if r != 0 : 9 10 print(r) 11 12 print('done') [2, 5, 0, 4, 3, 0, 10, 0, 8, 8, 20] 20 Noooo in tinn 5 2 done
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
