0% found this document useful (0 votes)
2 views3 pages

Practical Python Lessons Beginner

This document provides a series of practical Python lessons for beginners, covering fundamental concepts such as printing output, using variables, performing arithmetic operations, conditional statements, loops, lists, file handling, and building a simple command-line to-do list app. Each lesson includes objectives, tasks, and example code to help learners understand and apply Python programming skills. The lessons are structured to progressively build knowledge and confidence in coding with Python.

Uploaded by

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

Practical Python Lessons Beginner

This document provides a series of practical Python lessons for beginners, covering fundamental concepts such as printing output, using variables, performing arithmetic operations, conditional statements, loops, lists, file handling, and building a simple command-line to-do list app. Each lesson includes objectives, tasks, and example code to help learners understand and apply Python programming skills. The lessons are structured to progressively build knowledge and confidence in coding with Python.

Uploaded by

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

Practical Python Lessons for Beginners

Lesson 1: Getting Started - Hello World


Objective: Learn how to write and run your first Python program.

Task: Write a program that prints 'Hello, Python World!'.

Code:
print('Hello, Python World!')

Lesson 2: Variables and User Input


Objective: Practice using variables and taking input from the user.

Task: Ask the user for their name and age, then print a greeting.

Code:
name = input('What is your name? ')
age = input('How old are you? ')
print('Hello', name, '! You are', age, 'years old.')

Lesson 3: Calculator Using Arithmetic Operators


Objective: Perform basic arithmetic operations.

Task: Create a simple calculator that adds, subtracts, multiplies, and divides two numbers.

Code:
a = float(input('Enter first number: '))
b = float(input('Enter second number: '))
print('Sum:', a + b)
print('Difference:', a - b)
print('Product:', a * b)
print('Quotient:', a / b)

Lesson 4: Conditional Statements


Objective: Use if-else statements to make decisions.

Task: Write a program that checks if a number is even or odd.

Code:
num = int(input('Enter a number: '))
if num % 2 == 0:
print('Even')
else:
print('Odd')

Lesson 5: Loops - Guess the Number Game


Objective: Use loops and logic.

Task: User has to guess a number between 1 and 10. Give feedback.

Code:
import random
guess = 0
number = random.randint(1, 10)
while guess != number:
guess = int(input('Guess the number (1-10): '))
if guess < number:
print('Too low!')
elif guess > number:
print('Too high!')
else:
print('Correct!')

Lesson 6: Lists and Loops


Objective: Practice storing and looping through data.

Task: Store 5 student names and print them using a loop.

Code:
students = ['Alice', 'Bob', 'Cathy', 'David', 'Eve']
for student in students:
print('Student:', student)

Lesson 7: File Writing and Reading


Objective: Learn to save and read from files.

Task: Ask the user for a message, save it, then read it back.

Code:
msg = input('Write a message to save: ')
with open('message.txt', 'w') as file:
file.write(msg)

with open('message.txt', 'r') as file:


print('Saved message:', file.read())

Lesson 8: Build a To-Do List App (CLI)


Objective: Use lists, loops, and file handling in a project.

Task: Create a simple command-line to-do list.

Code:
# Add tasks
tasks = []
while True:
task = input('Enter a task (or type done): ')
if task.lower() == 'done':
break
tasks.append(task)

# Save tasks
with open('todo.txt', 'w') as file:
for task in tasks:
file.write(task + '\n')

# Read tasks
print('Your To-Do List:')
with open('todo.txt', 'r') as file:
for line in file:
print('-', line.strip())

You might also like