10 Loops Problems in Python.
In Python, loops are used to execute a block of code repeatedly. There are two main types of loops we will covering in this 10 Problems.
1)for loop:- A for loop is used to iterate over a sequence (such as a list, tuple, string, or range) or any iterable object.
2)While loop:- A while loop repeats a block of code as long as a specified condition is True.
Now let’s go through some problems using loops:-
1)Counting Positive Numbers.
Problem:-Given a list of numbers, count how many are positive.
List:- Numbers=[1,-2,3,-4,5,6,-7,-8,9,10]
Program:-
2)Sum of even numbers.
Problem:-Calculate the sum of even numbers up to a given number n.
Program:-
3)Multiplication Table Printer.
Problem:-Print the multiplication table for a given number up to 10, but skip the 5th iteration.
Program:-
4)Reverse a string.
Problem:-Reverse a string using loop.
Program:-
5)Find the first non-repeated character.
Problem:-Given a string, find the first non-repeated character using loop.
Program:-
6)Factorial Calculator.
Problem:-Compute the factorial of a number using a while loop.
Program:-
7)Validate Input.
Problem:-Keep asking the user for input until they enter a number between 1 and 10.
Program:-
8)Prime number checker.
Problem:-Check if a number is prime.
Program:-
9)List uniqueness checker.
Problem:-Check if all elements in a list are unique. If a duplicate is found exit the loop and print the duplicate.
List:- Items=[“apple”, ”banana”, ”orange”, ”apple”, ”orange”]
Program:-
10)Exponential Backoff.
Problem:-Implement an exponential backoff strategy that double the wait time between retries, starting from 1 second, but stops after 5 retries.
Program:-
So here are few 10 problems related to loops in Python.
This Content is been referred from the channel called Chai aur Code from YouTube:-
https://www.youtube.com/@chaiaurcode
and from the following video:-
https://youtu.be/v9bOWjwdTlg?si=yviqDKFKp67geFJC
Also follow my Instagram handle:-
https://www.instagram.com/yashpale_?igsh=MmVlMjlkMTBhMg==
Thanks for reading :0...