Share
Explore

Veerpal's Python Adventure

Python Lab workbook titled "Veerpal's Python Adventure", with 10 drills progressing from basic syntax to object-oriented programming concepts.
Each drill includes an explanation, an example, and an exercise for learners to practice.

Veerpal's Python Adventure

Welcome to "Veerpal's Python Adventure"! 🎉 This workbook is your gateway to mastering Python programming step by step. Whether you're a total beginner or just brushing up on your skills, these drills will guide you with clear explanations and fun exercises.
Remember: Every expert was once a beginner. Let's get started on this exciting journey!

Drill 1: Hello Python!

Concept: Printing to the console Python programs start with the basics: printing text!
Example:
python
print("Hello, Python!")

Exercise: Write a program that prints: ​"Welcome to Veerpal's Python Adventure!"

Drill 2: Variables and Data Types

Concept: Storing and using data with variables. Python variables can store numbers, text, and more!
Example:
python
name = "Veerpal"
age = 25
print(f"My name is {name} and I am {age} years old.")

Exercise: Create variables for your favorite color, number, and hobby. Print them in a sentence.

Drill 3: User Input

Concept: Interact with users by accepting input. Python's input() function allows the user to enter data.
Example:
python
name = input("What is your name? ")
print(f"Nice to meet you, {name}!")

Exercise: Write a program that asks the user for their favorite food and prints: ​"Yum! I love [food] too!"

Drill 4: Conditional Statements

Concept: Making decisions with if and else. Programs can behave differently based on conditions.
Example:
python
age = int(input("How old are you? "))
if age >= 18:
print("You are an adult!")
else:
print("You are a minor!")

Exercise: Write a program that checks if a number entered by the user is positive, negative, or zero.

Drill 5: Loops

Concept: Repeating tasks with loops. Use for and while loops to automate repetitive tasks.
Example:
python
for i in range(5):
print("Python is fun!")

Exercise: Write a program that prints the numbers 1 to 10 using a while loop.

Drill 6: Functions

Concept: Write reusable blocks of code. Functions allow you to organize and reuse your code.
Example:
python
def greet(name):
print(f"Hello, {name}!")

greet("Veerpal")

Exercise: Write a function square() that takes a number as input and returns its square.

Drill 7: Lists

Concept: Storing multiple items in a list. Lists are one of Python's most powerful data structures.
Example:
python
fruits = ["apple", "banana", "cherry"]
for fruit in fruits:
print(f"I love {fruit}!")

Exercise: Create a list of 5 of your favorite movies and print each one.

Drill 8: Dictionaries

Concept: Storing key-value pairs. Dictionaries allow you to map keys to values.
Example:
python
person = {"name": "Veerpal", "age": 25, "hobby": "coding"}
print(person["name"])

Exercise: Create a dictionary with keys "city", "country", and "population". Print each value.

Drill 9: File Handling

Concept: Reading from and writing to files. Python makes it easy to work with files.
Example:
python
with open("example.txt", "w") as file:
file.write("Hello, file!")

Exercise: Write a program that creates a file output.txt and writes "This is Veerpal's Python Adventure!" to it.

Drill 10: Classes and Objects

Concept: Introduction to Object-Oriented Programming (OOP). Classes are blueprints for creating objects.
Example:
python
class Dog:
def __init__(self, name, breed):
self.name = name
self.breed = breed

def bark(self):
print(f"{self.name} says Woof!")

my_dog = Dog("Buddy", "Golden Retriever")
my_dog.bark()

Exercise: Create a class Car with attributes brand and model, and a method drive() that prints "The [brand] [model] is driving!".

Congrats!

You’ve reached the end of Veerpal's Python Adventure! 🎉 Keep practicing, and remember: coding is a journey, not a destination. You're doing amazing! 🚀
If you need further clarification or want to expand on any of these drills, feel free to ask!

Veerpal's Python Adventure: Assignment 1

Welcome to your first assignment in Veerpal's Python Adventure! 🎉
This assignment will help you practice and reinforce the concepts you learned in the previous lessons. Each question is designed to test your understanding of Python basics, control structures, functions, data structures, file handling, and object-oriented programming. Let's dive in!

Instructions

Complete each question in a separate Python file or a single notebook cell (if using Jupyter Notebook).
Add comments to explain your code where necessary.
Test your code thoroughly to ensure it works as expected.
Submit your completed assignment as a .zip file containing all your Python files or as a single .ipynb notebook.

Assignment Questions

1. Hello Python!

Write a Python program that prints the following message to the console:"Welcome to Veerpal's Python Adventure! Let's start coding!"

2. Variables and Data Types

Create a program that:
Declares variables for your name, age, and favorite programming language.
Prints a sentence using these variables, such as: ​"Hi, my name is Veerpal. I am 25 years old, and my favorite programming language is Python!"

3. User Input

Write a program that:
Asks the user for their name and favorite hobby.
Prints a personalized message, such as: ​"Hi [name]! It's great that you enjoy [hobby]!"

4. Conditional Statements

Write a program that:
Asks the user to enter a number.
Checks if the number is positive, negative, or zero, and prints an appropriate message.

5. Loops

Write a program that:
Prints the numbers from 1 to 20 using a for loop.
Then, prints the same numbers in reverse order using a while loop.

6. Functions

Write a function called calculate_area() that:
Takes the length and width of a rectangle as arguments.
Returns the area of the rectangle.
Call the function with sample values and print the result.

7. Lists

Write a program that:
Creates a list of 5 of your favorite foods.
Prints each food item in the list using a for loop.
Adds a new food item to the list and prints the updated list.

8. Dictionaries

Write a program that:
Creates a dictionary with the following keys: "name", "age", and "city".
Assigns appropriate values to these keys.
Prints a sentence using the dictionary values, such as: ​"My name is Veerpal, I am 25 years old, and I live in Toronto."

9. File Handling

Write a program that:
Creates a file called adventure.txt.
Writes the following text to the file: ​"This is Veerpal's Python Adventure! Keep learning and coding!"
Reads the content of the file and prints it to the console.

10. Classes and Objects

Write a Python class called Book that:
Has attributes for title, author, and year.
Includes a method get_info() that prints the book's details in the format: ​"Title: [title], Author: [author], Year: [year]"
Create an object of the Book class with sample data and call the get_info() method.

Bonus Challenge (Optional)

Write a program that:
Asks the user to enter a list of numbers separated by commas (e.g., 1,2,3,4,5).
Converts the input into a list of integers.
Calculates and prints the sum, average, maximum, and minimum of the numbers.

Submission Guidelines

Ensure your code is well-commented and easy to read.
Test each program thoroughly before submission.
Submit your assignment as a .zip file containing all your Python files or as a single .ipynb notebook.

Grading Criteria

CriteriaPoints
Correctness of Code 50
Code Readability (Comments)20
Creativity and Effort 20
Bonus Challenge 10

Good Luck!

You’ve got this! Remember, programming is all about practice and persistence. If you get stuck, take a deep breath, review the lesson materials, and try again. Happy coding! 🚀
Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.