0% found this document useful (0 votes)
7 views3 pages

For, While List (QP)

This document provides notes and tasks related to for and while loops in Python. It includes examples and a series of programming tasks aimed at practicing loop concepts, such as printing numbers, calculating sums, and manipulating lists. The tasks range from basic to more complex operations, encouraging the application of loops in various scenarios.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views3 pages

For, While List (QP)

This document provides notes and tasks related to for and while loops in Python. It includes examples and a series of programming tasks aimed at practicing loop concepts, such as printing numbers, calculating sums, and manipulating lists. The tasks range from basic to more complex operations, encouraging the application of loops in various scenarios.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Year 11 – Worksheet

For and while loop

Notes

For loop in python: For loops in Python iterate over a sequence (such as a list, tuple, string, or range)
and execute a block of code multiple times. They're beneficial for performing repetitive tasks efficiently
and can handle numerical and non-numerical data.

Example :

for i in range(5,10):

print i

output:

Task

Q1. Print the first 10 natural numbers using for loop

Q2. Python program to print all the even numbers within a given range

Q3. Python program to calculate sum of all numbers from 1 to a given number

Q4. Python program to calculate sum of all odd numbers within the given range

Q5. Python program to print a multiplication table of a given number

Q6. Python program to display all numbers from a list using a for loop

Q7. Python program to count the total number of digits in a number

Q8. Write a Python program that calculates the sum of all elements in a given list.

Example: Given the list [1, 2, 3, 4, 5], the program should output 15

Q9. Write a Python program that finds the largest number in a given list

Example: Given the list [10, 20, 4, 45, 99], the program should output 99
Q10. Write a Python program that counts how many times a specific element appears in a list.

Example: Given the list [1, 2, 2, 3, 4, 4, 4, 5] and the target number 4, the program should
output 3

Q11. Write a Python program that prints all the even numbers from a given list

Example:Given the list [1, 2, 3, 4, 5, 6, 7, 8, 9], the program should output 2, 4, 6, 8

Q12. Write a Python program that creates a new list containing the squares of all elements in a
given list.
Example: Given the list [1, 2, 3, 4], the program should output [1, 4, 9, 16]
Q13. Write a Python program that creates a new list containing only the positive numbers from a
given list.
Example: Given the list [-1, 2, -3, 4, 5, -6], the program should output [2, 4, 5]
Q14. Write a Python program that concatenates all the strings in a given list into a single string.

Example: Given the list ["hello", "world", "python"], the program should output
"helloworldpython"

Q15. Write a Python program that calculates the product of all numbers in a list

Example: Given the list [2, 3, 4], the program should output 24

Q16. Write a Python program that creates a new list containing the lengths of each string in a given list.

Example: Given the list ["apple", "banana", "cherry"], the program should output [5, 6, 6].

Q17. Write a Python program using a while loop to find the sum of all the numbers in a list.
Example: Given the list [1, 2, 3, 4, 5], the program should output 15

Q18. Write a Python program using a while loop to count how many times a specific number
appears in a list. Example: Given the list [1, 2, 3, 4, 2, 2, 5] and the number 2, the
program should output 3

Q19. Write a Python program using a while loop to reverse a list. Example: Given the list [1,
2, 3, 4, 5], the program should output [5, 4, 3, 2, 1]

Q20. Write a Python program using a while loop to find the smallest number in a list. Example:
Given the list [10, 20, 4, 45, 99], the program should output 4

Q21. Write a Python program using a while loop to find the greatest number in a list. Example:
Given the list [10, 20, 4, 45, 99], the program should output 99

Q22. Write a Python program with a list consisting of both positive and negative numbers.
Ensure that the smallest number is found correctly
Q23. Write a Python program that counts how many times a specific element (given by the user)
occurs in a list using a while loop.

Q24. Create a list with elements 9,8,7,6,5.

Ask the user whether they need to change any element, if the user enter “Y” – then ask for the
index and element to be inserted and change the elements in the list accordingly

Repeat it until the user enters “N” and print the new list

You might also like