0% found this document useful (0 votes)
0 views2 pages

Python For and While Loop

The document provides a series of programming exercises categorized into Beginner, Intermediate, Challenging, and Advanced levels. Each level contains specific tasks that involve using for and while loops to perform various operations such as printing numbers, calculating sums, and manipulating strings and lists. The exercises aim to enhance coding skills and understanding of loop structures in programming.

Uploaded by

Sushant Patil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views2 pages

Python For and While Loop

The document provides a series of programming exercises categorized into Beginner, Intermediate, Challenging, and Advanced levels. Each level contains specific tasks that involve using for and while loops to perform various operations such as printing numbers, calculating sums, and manipulating strings and lists. The exercises aim to enhance coding skills and understanding of loop structures in programming.

Uploaded by

Sushant Patil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Beginner Level

1.​ Write a for loop to print numbers from 1 to 10.


2.​ Write a while loop to print numbers from 1 to 10.
3.​ Use a for loop to print each character in the string "Python".
4.​ Use a while loop to print each character in the string "Python".
5.​ Use a for loop to print all elements in a list [10, 20, 30, 40, 50].
6.​ Use a while loop to iterate through the same list.
7.​ Write a for loop to print even numbers from 2 to 20.
8.​ Write a while loop to print odd numbers from 1 to 19.
9.​ Write a for loop with range() to print numbers from 5 to 1 in reverse order.
10.​Write a while loop that keeps asking the user to enter a number until they enter 0.

Intermediate Level
11.​Use a for loop with range() to calculate the sum of numbers from 1 to 100.
12.​Use a while loop to calculate the factorial of a given number.
13.​Write a loop to find the largest number in a list [45, 67, 23, 89, 12].
14.​Use a for loop to print a multiplication table of 5.
15.​Use a while loop to reverse a given number (e.g., 12345 → 54321).
16.​Use nested for loops to print a 5x5 star (*) pattern.
17.​Write a while loop to count the number of digits in a given number.
18.​Write a for loop to iterate over a dictionary and print keys and values
19.​Use a while loop with a break statement to stop when a condition is met.
20.​Use a for loop with an else block to print a message when the loop ends normally.

Challenging Level
21.​Write a for loop to find all prime numbers between 1 and 50.
22.​Write a while loop that generates Fibonacci numbers less than 100.
23.​Use a nested loop to print a right-angled triangle pattern of numbers.
24.​Use a while loop with continue to skip printing multiples of 3 from 1 to 20.
25.​Use a for loop with enumerate() to print index and value for a list.
26.​Use a for loop to flatten a nested list [[1,2],[3,4],[5,6]].
27.​Use a while loop to simulate a simple login attempt with 3 tries.
28.​Write a for loop that uses zip() to iterate over two lists simultaneously.
29.​Write a while loop to find the GCD (greatest common divisor) of two numbers.
30.​Use a for loop with a list comprehension to create a list of squares from 1 to 10.

Advanced Level
31.​Use a for loop to implement bubble sort on a list.
32.​Use a while loop to simulate a basic ATM that continues until the balance is zero.
33.​Write nested loops to print a pyramid pattern with numbers
34.​Write a loop to count vowels and consonants in a string.
35.​Use a for loop to read lines from a file and print them.
36.​Write a while loop that finds the square root of a number using the
Newton-Raphson method.​

37.​Use nested for loops to generate all pairs (i, j) where i and j are from 1 to 3
38.​Use a for loop to check if a string is a palindrome.
39.​Write a while loop to simulate rolling a dice until you get a six.
40.​Combine for and while loops to solve a small maze represented as a 2D grid.

You might also like