Python Practical Assignment 11.1

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

  1. Start the program.
  2. Create a list with some numbers.
  3. Use a for loop to go through each element.
  4. Check if the element is less than 10.
  5. If true, print the element.
  6. 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.


Spread the love

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top