Python Programming Lab Manual
Course Title
Data Structure
Lab Objective
This lab manual is designed to help students understand the while loop in
Python through very simple programs. Students will be able to write, run,
and understand basic while-loop-based programs using Visual Studio Code
(VS Code).
Software Requirements
Python 3.x
Visual Studio Code (VS Code)
Python Extension for VS Code
Lab 1: While Loop in Python (All Tasks)
Aim
To understand and implement the while loop in Python for repetition and
iteration.
Task 1: Print Numbers from 1 to 5
Program
i = 1
while i <= 5:
print(i)
i = i + 1
Task 2: Print Numbers from 1 to 10
Program
i = 1
while i <= 10:
print(i)
i += 1
Task 3: Print Even Numbers up to 10
Program
i = 2
while i <= 10:
print(i)
i += 2
Task 4: Print a Message 5 Times
Program
i = 1
while i <= 5:
print("Welcome to Python Lab")
i += 1
Task 5: Sum of First 5 Natural Numbers
Program
i = 1
sum = 0
while i <= 5:
sum = sum + i
i += 1
print("Sum is:", sum)
Task 6: Table of a Number
Program
num = int(input("Enter a number: "))
i = 1
while i <= 10:
print(num, "x", i, "=", num * i)
i += 1
Lab Instructions for Students
Save the file with .py extension.
Run the program using VS Code terminal.
Observe the output.
Do not forget to update the loop variable.