Write a Python Program to Print All Elements of the List That Are Less Than 10
Introduction
In Python, we can use a loop to check each element in a list. This program prints only those elements that are less than 10.
Logic to Write the Code
- Start the program.
- Create a list with some numbers.
- Use a
forloop to go through each element. - Check if the element is less than 10.
- If true, print the element.
- End the program.
Source Code (Beginner Friendly)
# Python program to print elements less than 10
# Creating a list
numbers = [5, 12, 3, 25, 8, 15, 1]
# Checking and printing elements less than 10
for num in numbers:
if num < 10:
print(num)
Sample Output
5
3
8
1
Viva Questions with Answers
1. What is a list in Python?
A list is a collection of elements stored in a single variable.
2. Which loop is used to access list elements?
The for loop is commonly used.
3. What does if num < 10 check?
It checks whether the number is less than 10.
4. Can we store different data types in a list?
Yes, Python lists can store different data types.
5. What will happen if no element is less than 10?
Nothing will be printed.
