Python Course — Day 2

Your First Python Program

Today you'll master the terminal, install Python, and write real programs that make your computer do what you tell it. By the end, you'll be a person who can code.

Lab Modules

📌 Important Setup Note

Throughout this lab, we'll use PowerShell as our terminal. We'll store all our course files in H:\Pooja. Make sure you can see the H: drive on your computer before starting.

Terminal Warm-Up — PowerShell Recap

Let's refresh what we learned last time and learn a few more useful commands. Remember: the terminal is just a text-based way to talk to your computer.

💡 Quick Recap from Day 0

The terminal is a text window where you type commands. You type a command, press Enter, and the computer does what you asked. Today we'll use PowerShell — Windows' modern terminal. It works the same way as Command Prompt but has more features.

TASK 1.1 Open PowerShell
  1. Press the Windows key on your keyboard (the key with the Windows logo, usually between Ctrl and Alt).
  2. Type powershell — you'll see "Windows PowerShell" appear in the search results.
  3. Click on it. A blue/dark window will open with text. This is PowerShell — your terminal.
  4. You'll see something like this:
PowerShell
PS C:\Users\YourName> _

The PS at the start means you're in PowerShell. The path after it (C:\Users\YourName) is the folder you're currently "standing in."

TASK 1.2 Recap — Try These Commands Again

Type each of these commands and press Enter after each one. Observe the result before moving to the next.

Warm-up commands
# 1. Where am I right now? PS C:\Users\YourName> pwd Path ---- C:\Users\YourName # 2. What files and folders are here? PS C:\Users\YourName> ls Directory: C:\Users\YourName Mode Name ---- ---- d---- Desktop d---- Documents d---- Downloads -a--- notes.txt # 3. Who am I? PS C:\Users\YourName> whoami lab-pc\yourname # 4. Repeat text back to me PS C:\Users\YourName> echo "I am learning PowerShell" I am learning PowerShell # 5. Clear the screen PS C:\Users\YourName> cls
TASK 1.3 New Commands — Get More Information

Here are some new commands. Try each one.

New commands
# Show today's date and time PS> Get-Date Monday, March 30, 2026 10:30:15 AM # Show your computer's IP address (how others find you on a network) PS> ipconfig Windows IP Configuration IPv4 Address. . . . . . : 192.168.1.105 ... # Show the last 5 commands you typed (your history!) PS> Get-History Id CommandLine -- ----------- 1 pwd 2 ls 3 whoami ... # Tip: You can also press the UP ARROW key to scroll # through your previous commands. Try it now!
  1. Try each command above.
  2. Press the Up Arrow key a few times. See how it brings back your previous commands? This is a huge time-saver — you don't have to re-type everything.
  3. Press the Down Arrow to go forward through your history. Press Escape to clear the current line.

Paths & Navigation — Drives, Folders, and Addresses

Every file has a full address called a path. Today we'll navigate between two different drives (C: and H:) and become confident moving around your computer from the terminal.

💡 Your Computer Has Multiple Drives

Think of drives as separate buildings. C: is the main building where Windows lives. H: is another building (maybe a network drive or a second hard disk your school provides). Each building has its own rooms (folders) and papers (files). To get to a room in a different building, you first need to go to that building.

💡 Key Path Commands Cheat Sheet

pwd — "Where am I right now?" (Print Working Directory)
cd foldername — Go into a folder
cd .. — Go up one folder (to the parent)
cd \ — Go to the root of the current drive
cd H:\Pooja — Jump directly to a specific path (any drive)
H: — Switch to the H: drive (just type the drive letter and colon)

TASK 2.1 Navigate Between the C: and H: Drives
Switching drives
# Step 1: You start on the C: drive PS C:\Users\YourName> pwd C:\Users\YourName # Step 2: Switch to the H: drive PS C:\Users\YourName> cd H:\ PS H:\> _ # Step 3: See what's on the H: drive PS H:\> ls Directory: H:\ Mode Name ---- ---- d---- Pooja d---- OtherStuff # Step 4: Go into the Pooja folder PS H:\> cd Pooja PS H:\Pooja> _ # Step 5: Switch back to C: drive PS H:\Pooja> cd C:\ PS C:\> _ # Step 6: Jump directly to H:\Pooja from anywhere PS C:\> cd H:\Pooja PS H:\Pooja> _
  1. Follow every step above in your PowerShell. Watch the prompt change as you move.
  2. Make sure you can see H:\Pooja in your prompt before continuing. If the Pooja folder doesn't exist yet, we'll create it in the next module.
TASK 2.2 Navigation Drills — Practice Moving Around

Starting from H:\Pooja, follow these navigation instructions exactly. After each step, type pwd to confirm you're in the right place.

Navigation drill
# Start here PS H:\Pooja> cd C:\Users PS C:\Users> pwd C:\Users PS C:\Users> cd .. PS C:\> pwd C:\ PS C:\> cd Users\YourName\Desktop PS C:\Users\YourName\Desktop> pwd C:\Users\YourName\Desktop PS C:\Users\YourName\Desktop> cd .. PS C:\Users\YourName> cd .. PS C:\Users> cd .. PS C:\> _ # Now jump all the way back to H:\Pooja in one command: PS C:\> cd H:\Pooja PS H:\Pooja> _
📝 Quiz — Predict the Output

You are at PS C:\Users\YourName\Desktop>. You type cd .. and press Enter. What will the new prompt show?

A PS C:\Users\YourName\Desktop\..>
B PS C:\>
C PS C:\Users\YourName>
D PS H:\Pooja>
Correct! cd .. goes up one folder. From Desktop, one folder up is YourName. So the prompt becomes PS C:\Users\YourName>.
📝 Quiz — Predict the Output

You are at PS H:\>. You type cd Pooja then cd .. then cd ... Where are you now?

A PS H:\Pooja>
B PS H:\>
C PS C:\>
D Error — you can't go above H:\
Correct! cd Pooja takes you to H:\Pooja. First cd .. takes you back to H:\. Second cd .. tries to go above H:\ but you're already at the root — so you stay at H:\. You can't go above the root of a drive.
📝 Quiz — Predict the Output

You type cd H:\Pooja from PS C:\Windows\System32>. What does the prompt show?

A PS H:\Pooja>
B PS C:\Windows\System32\H:\Pooja>
C Error — you can't switch drives with cd
D PS C:\Pooja>
Correct! When you give cd a full path (starting with a drive letter like H:\), it jumps directly there — no matter where you currently are. This is called an absolute path.
📝 Quiz — Predict the Output

Which of these is a file path (not a folder path)?

A H:\Pooja
B C:\Users\YourName\Desktop
C C:\Windows
D H:\Pooja\hello.py
Correct! A file path ends with a file name that has an extension (like .py). H:\Pooja\hello.py points to a specific file. The others point to folders.

Creating Files & Folders from the Terminal

Last time you created files and folders by right-clicking. Today you'll do it the programmer way — from the terminal. This is faster and the way you'll do it throughout the course.

TASK 3.1 Create the Course Folder (If It Doesn't Exist)
Creating a folder
# First, go to the H: drive PS> cd H:\ # Create the Pooja folder (mkdir = "make directory") PS H:\> mkdir Pooja Directory: H:\ Mode Name ---- ---- d---- Pooja # Go inside it PS H:\> cd Pooja PS H:\Pooja> _
  1. Type the commands above. If the folder already exists, PowerShell will tell you — that's fine, just cd into it.
  2. Now open File Explorer (press Windows + E). Navigate to the H: drive. You should see the Pooja folder there! You created it from the terminal, but it's a real folder — visible everywhere.
TASK 3.2 Create a Sub-Folder
Sub-folder
# Make sure you're inside H:\Pooja PS H:\Pooja> mkdir day2 Directory: H:\Pooja Mode Name ---- ---- d---- day2 PS H:\Pooja> cd day2 PS H:\Pooja\day2> _
  1. Create the day2 folder and go inside it.
  2. Check File Explorer again — you should see day2 inside Pooja.
TASK 3.3 Create a File from the Terminal
Creating a file
# Make sure you're inside H:\Pooja\day2 PS H:\Pooja\day2> New-Item -Name "practice.txt" -ItemType "File" Directory: H:\Pooja\day2 Mode Name ---- ---- -a--- practice.txt # Verify it's there PS H:\Pooja\day2> ls -a--- practice.txt

You just created an empty file called practice.txt from the terminal. Check File Explorer — it's there!

TASK 3.4 Open Notepad from the Terminal, Edit, and Save
Opening Notepad
# Open the file in Notepad directly from terminal PS H:\Pooja\day2> notepad practice.txt
  1. Type the command above and press Enter. Notepad will open with the empty file.
  2. Inside Notepad, type: My name is [your name]. I am learning Python today!
  3. Press Ctrl + S to save the file.
  4. Close Notepad (click the X or press Alt+F4).
  5. Now, back in PowerShell, read the file's contents:
Reading the file
PS H:\Pooja\day2> Get-Content practice.txt My name is Pooja. I am learning Python today!

Get-Content is the PowerShell command to read a file's contents and print them in the terminal. You edited a file in Notepad and confirmed the changes from the terminal — both tools see the same file.

TASK 3.5 Write to a File Directly from the Terminal

You can also put text into a file without even opening Notepad:

Writing to a file
# Write text directly into a new file PS H:\Pooja\day2> "Hello from PowerShell!" | Out-File greeting.txt # Read it back to confirm PS H:\Pooja\day2> Get-Content greeting.txt Hello from PowerShell! # List all files — you should now have 2 files PS H:\Pooja\day2> ls -a--- greeting.txt -a--- practice.txt

Checking If Software Is Installed

Before installing Python, let's first check if it's already on this computer. There's a simple way to check from the terminal.

💡 How to Check If a Program Is Installed

The easiest way to check if a program is installed and ready to use is to try running it. If the terminal says "not recognized" — it's either not installed or not set up properly. If it shows a version number or opens the program — it's installed and working.

TASK 4.1 Check If Python Is Already Installed
Checking for Python
# Method 1: Try running python with --version flag PS H:\Pooja\day2> python --version # IF Python is installed, you'll see something like: Python 3.12.4 # IF Python is NOT installed, you'll see something like: python : The term 'python' is not recognized as the name of a cmdlet, function, script file, or operable program.
  1. Type python --version and press Enter.
  2. Also try python3 --version — some installations use python3 instead of python.
  3. Write down what you see. Did you get a version number, or an error?
TASK 4.2 Try Checking Other Programs Too

Let's practice this skill by checking for other programs. Try each:

Checking other programs
# Check if Git is installed PS> git --version # Check if Node.js is installed PS> node --version # Check if Java is installed PS> java --version

The pattern is always the same: type the program name followed by --version. If you get a version number, it's installed. If you get an error, it's not (or it's not in the PATH — we'll cover that soon).

📝 Quiz

You type python --version and see Python 3.11.5. What does this mean?

A Python needs to be updated
B Python version 3.11.5 is installed and working
C Python is installed but not in the PATH
D Python installation failed
Correct! If the terminal shows a version number, it means the program is installed AND the terminal knows where to find it. Everything is working.

Downloading & Installing Python

If Python is not installed (or you want a fresh install), follow these steps. We'll install it from the terminal — the programmer way. Since you're not an admin on this computer, we'll install it just for your user account.

⚠️ Already Have Python?

If python --version already shows Python 3.10 or higher — skip this module and go to Module 6. No need to install again!

💡 What We're About to Do

We will: (1) Download the Python installer from the internet — this copies a file to your computer. (2) Run the installer — this sets up Python on your computer so you can use it. We'll use PowerShell commands for both steps. The installation will be "per-user" which means it doesn't need admin permission.

TASK 5.1 Download the Python Installer

We'll use a PowerShell command to download the installer file from the official Python website.

Downloading Python
# Step 1: Navigate to your day2 folder PS> cd H:\Pooja\day2 # Step 2: Download the Python installer # This command downloads a file from the internet # Invoke-WebRequest = "go to this website and download something" # -Uri = the web address of the file # -OutFile = what to name the downloaded file PS H:\Pooja\day2> Invoke-WebRequest -Uri "https://www.python.org/ftp/python/3.12.4/python-3.12.4-amd64.exe" -OutFile "python-installer.exe" # This will take a minute or two. You'll see a progress bar. # Wait until the prompt comes back. # Step 3: Verify the file was downloaded PS H:\Pooja\day2> ls python-installer.exe -a--- 24985432 python-installer.exe
  1. Type the Invoke-WebRequest command carefully (or copy it from the screen if your instructor provides it). Press Enter.
  2. Wait for the download to finish. You'll see a progress bar. It might take 1–3 minutes.
  3. Once done, type ls python-installer.exe to make sure the file exists. You should see the file with a large size (about 25 million bytes).

You just downloaded a file using the terminal instead of a browser. The file python-installer.exe is now sitting in H:\Pooja\day2 — you can see it in File Explorer too.

TASK 5.2 Install Python (For Current User Only)

Now we run the installer. The special flags tell it to install just for you (no admin needed) and to add Python to the PATH automatically.

Installing Python
# Run the installer with these flags: # /quiet = don't show the graphical installer window # InstallAllUsers=0 = install for current user only (no admin needed) # PrependPath=1 = add Python to PATH (very important!) # Include_pip=1 = include pip (a tool to install Python packages) PS H:\Pooja\day2> .\python-installer.exe /quiet InstallAllUsers=0 PrependPath=1 Include_pip=1 # This will take 2-5 minutes. The screen won't show much. # Just wait patiently until the prompt returns.
  1. Type the command above exactly and press Enter.
  2. Be patient. The installation runs silently (no windows pop up). Wait until you see the prompt again — that means it's done.
  3. The installation is complete when the prompt returns.
TASK 5.3 Close and Reopen PowerShell
  1. Close PowerShell completely — click the X button on the PowerShell window.
  2. Open a new PowerShell window (Windows key → type "powershell" → click it).
  3. Navigate back to your folder: type cd H:\Pooja\day2
⚠️ Why Close and Reopen?

The PATH (the list of locations where the terminal looks for programs) is loaded when the terminal starts. Since we just added Python to the PATH during installation, we need to restart the terminal so it picks up this change. The old terminal window still has the old PATH.

TASK 5.4 Verify Python Is Installed
Verifying installation
PS H:\Pooja\day2> python --version Python 3.12.4

If you see a version number — congratulations, Python is installed! If you still see an error, move on to Module 6 where we'll troubleshoot it.


Running Python & Understanding the PATH

Let's understand why typing python works — and what to do if it doesn't.

TASK 6.1 Run the Python Command
Running Python
PS H:\Pooja\day2> python --version Python 3.12.4

💡 Why Does Typing "python" Work?

When you type python, here's what happens behind the scenes:

1. The terminal reads your command: python
2. It asks: "Where is a program called 'python'?"
3. It looks through a list of folders called the PATH
4. It finds python.exe in one of those folders
5. It runs that program

The PATH is just a setting — a list of folder locations stored in your computer. When the terminal needs to find a program, it checks each folder in the PATH list, one by one, until it finds the program. That's it — nothing magical.

TASK 6.2 See Where Python Is Installed
Finding Python's location
# Ask PowerShell: "Where is the python program?" PS> Get-Command python | Select-Object Source Source ------ C:\Users\YourName\AppData\Local\Programs\Python\Python312\python.exe

See that? Python was installed to a folder deep inside your user account. The terminal knows to look there because that folder was added to the PATH during installation.

TASK 6.3 See the Entire PATH List
Viewing the PATH
# Show all the folders in the PATH — one per line PS> $env:PATH -split ";" C:\Users\YourName\AppData\Local\Programs\Python\Python312\ C:\Users\YourName\AppData\Local\Programs\Python\Python312\Scripts\ C:\Windows\system32 C:\Windows C:\Program Files\... ...
  1. Run the command above. You'll see a long list of folders.
  2. Look through the list. You should see a line containing Python. That's the line that was added during installation.
  3. The terminal checks each of these folders whenever you type a command. If it finds a matching .exe in any of them, it runs it.

💡 What If "python" Doesn't Work? — Don't Panic!

If you get an error like "not recognized," it just means the PATH setting doesn't include Python's folder. The fix is to add Python's folder to the PATH. Here's how:

TASK 6.4 Manually Add Python to PATH (Only If Needed)

Skip this if python --version already works. Only do this if you get the "not recognized" error.

Fixing the PATH (only if needed)
# Step 1: Find where Python was installed # Look in these common locations: PS> Test-Path "$env:LOCALAPPDATA\Programs\Python\Python312\python.exe" True # If the above says "True", Python IS installed, the PATH is just missing it. # Step 2: Add Python to your PATH for this session (temporary) PS> $env:PATH = "$env:LOCALAPPDATA\Programs\Python\Python312;$env:LOCALAPPDATA\Programs\Python\Python312\Scripts;$env:PATH" # Step 3: Test it now PS> python --version Python 3.12.4 # Step 4: To make it permanent (so it works every time you open PowerShell): PS> [Environment]::SetEnvironmentVariable("PATH", "$env:LOCALAPPDATA\Programs\Python\Python312;$env:LOCALAPPDATA\Programs\Python\Python312\Scripts;" + [Environment]::GetEnvironmentVariable("PATH", "User"), "User")

Don't be intimidated by that long command. All it does is add Python's folder to the saved list of PATH folders. You only need to do this once. After this, python will work every time you open PowerShell.

📝 Quiz

What is the PATH?

A The location of a specific file like C:\Pooja\hello.py
B A command that runs Python programs
C A saved list of folders where the terminal looks for programs
D The internet address of a website
Correct! The PATH is a setting stored in your computer that contains a list of folder locations. When you type any command, the terminal searches these folders to find the program you asked for. It's like a phone's contact list — you just type a name and the phone knows which number to call.

Command-Line Arguments — Talking to Programs

When you type python --version, you're not just running Python — you're running Python and telling it something. That --version part is called an argument.

🏠 Real-World Analogy

Think of going to a coffee shop. You say: "Coffee, large, no sugar."

coffee = the program (what you want)
large = an argument (how you want it)
no sugar = another argument (more instructions)

In the terminal: python --version
python = the program
--version = the argument ("just tell me your version, don't do anything else")

TASK 7.1 See Different Arguments in Action

The same program can do completely different things depending on what arguments you give it:

Arguments in action
# Argument: --version → just show version and exit PS> python --version Python 3.12.4 # Argument: -c "code" → run a tiny piece of Python code directly PS> python -c "print('Hello from an argument!')" Hello from an argument! # Argument: -c with math PS> python -c "print(2 + 2)" 4 # No arguments at all → opens Python's interactive mode PS> python Python 3.12.4 (tags/v3.12.4:8e8a4ba, Jun 6 2024) Type "help", "copyright", "credits" or "license" for more information. >>> # You're now INSIDE Python! Type exit() to get back to PowerShell: >>> exit() PS> _
  1. Try each command above. Notice how the same program (python) does completely different things depending on the arguments.
  2. When you run python without arguments and see >>>, you're inside Python's interactive mode. Type exit() to get back to PowerShell.
TASK 7.2 Arguments Work with Other Programs Too
More argument examples
# ping with an argument (the website to ping) PS> ping google.com # notepad with an argument (the file to open) PS> notepad H:\Pooja\day2\practice.txt # echo with an argument (the text to repeat) PS> echo "Arguments are easy!"

Every command you've been using has been: program name followed by arguments. cd H:\Pooja = program cd, argument H:\Pooja. You've been using arguments all along!


Your First Python Program — Hello, World!

This is it. The moment you become a programmer. You're about to write a Python program and run it.

TASK 8.1 Create Your First Python File
  1. Make sure you're in H:\Pooja\day2:
Creating hello.py
PS> cd H:\Pooja\day2 # Open a new file called hello.py in Notepad PS H:\Pooja\day2> notepad hello.py # Notepad will ask "Do you want to create a new file?" — click YES
  1. In Notepad, type exactly this one line:
PYTHONhello.py
print("Hello, World!")
  1. Press Ctrl + S to save.
  2. Close Notepad.
TASK 8.2 Run Your Program!
Running hello.py
PS H:\Pooja\day2> python hello.py Hello, World!

Look at that! Your computer just did what you told it to do. You wrote an instruction in Python (print("Hello, World!")) and the computer followed it. hello.py is the argument — it tells Python which file to read and run.

🎉

You Just Wrote Your First Program!

Every programmer in history started exactly here — with "Hello, World!" You are now officially someone who can write and run code.

TASK 8.3 Edit and Re-Run — Make It Yours
  1. Open the file again: notepad hello.py
  2. Change the text to say something about you. For example:
PYTHONhello.py
print("Hello! My name is Pooja and I just learned Python!")
  1. Save (Ctrl + S), close Notepad.
  2. Run it again:
Running the edited program
PS H:\Pooja\day2> python hello.py Hello! My name is Pooja and I just learned Python!

The cycle is: Edit → Save → Run. This is the cycle you'll follow thousands of times as a programmer. You change the code, save the file, and run it again to see the result.

TASK 8.4 Take Input from the User

Let's make the program interactive — it will ask for your name and respond to it.

  1. Open the file: notepad hello.py
  2. Replace everything with this:
PYTHONhello.py
name = input("What is your name? ") print("Nice to meet you,", name, "! Welcome to Python!")
  1. Save and close. Run it:
Interactive program
PS H:\Pooja\day2> python hello.py What is your name? Pooja Nice to meet you, Pooja ! Welcome to Python!

The program waited for you to type something! input() pauses the program and waits for the user to type something and press Enter. Then it stores whatever they typed and uses it later. You just made the computer listen to you and respond.


Input → Process → Output

Every program you will ever write — from a simple greeting to a video game — does one or more of these three things.

INPUT Get data from user PROCESS Do something with it OUTPUT Show the result

💡 The IPO Model

Input = getting data (from the keyboard, a file, the internet, etc.)
Process = doing something with that data (math, decisions, sorting, combining, etc.)
Output = showing the result (on screen, saving to a file, sending over the internet, etc.)

Your "Hello World" was just Output. Your name program was Input → Process → Output. Let's see more examples.

TASK 9.1 Multiple Print Statements — Output Only

Create a new file called about_me.py and paste this:

Create the file
PS H:\Pooja\day2> notepad about_me.py
PYTHONabout_me.py
print("=========================") print(" ALL ABOUT ME") print("=========================") print("Name : Pooja") print("Course : Python Programming") print("Day : 2") print("Mood : Excited!") print("=========================")
  1. Paste or type the code above. Edit the details to be about you — change the name, add a line about your hobby, change the mood.
  2. Save, close, and run: python about_me.py
  3. You can have as many print() statements as you want. Each one prints one line. The program runs them top to bottom, one at a time.
TASK 9.2 Input → Process → Output: A Complete Program

Create a new file called birth_year.py:

Create the file
PS H:\Pooja\day2> notepad birth_year.py
PYTHONbirth_year.py
# INPUT: Ask the user for their age age = input("How old are you? ") # PROCESS: Calculate their birth year birth_year = 2026 - int(age) # OUTPUT: Show the result print("You were probably born in", birth_year)
  1. Copy and paste the code. Save and run: python birth_year.py
  2. When it asks for your age, type a number (like 20) and press Enter.
  3. Notice the three parts: Input (asks your age), Process (calculates 2026 minus your age), Output (shows the birth year).
Running birth_year.py
PS H:\Pooja\day2> python birth_year.py How old are you? 20 You were probably born in 2006

Cool Programs You Can Already Run

Let's see what Python can do. For each program below: create the file, paste the code, run it, and try to guess how it works before reading the explanation. No stress — just have fun.

TASK 10.1 Countdown Timer
Create and run
PS H:\Pooja\day2> notepad countdown.py
PYTHONcountdown.py
import time print("Rocket Launch Countdown!") print() for i in range(10, 0, -1): print(i, "...") time.sleep(1) print("LIFTOFF! 🚀")
  1. Paste the code, save, and run: python countdown.py
  2. Watch the countdown happen in real time — one number per second!
  3. Can you guess? What does time.sleep(1) probably do? What does range(10, 0, -1) probably mean?
🤔 What do you think?

What does time.sleep(1) do?

time.sleep(1) tells Python to wait 1 second before continuing. That's why the numbers appear one per second. If you changed it to time.sleep(3), it would wait 3 seconds between each number.
TASK 10.2 Random Compliment Generator
Create and run
PS H:\Pooja\day2> notepad compliment.py
PYTHONcompliment.py
import random name = input("What is your name? ") compliments = [ "You are doing amazing work!", "You are a fast learner!", "Your dedication is inspiring!", "You have a great attitude!", "The world needs more people like you!", ] print() print(name + ", here is your compliment:") print(">> " + random.choice(compliments))
  1. Paste the code, save, and run: python compliment.py
  2. Run it 3 or 4 times. Notice you get different compliments each time!
  3. Try editing: Add your own compliment to the list (add a new line inside the square brackets, following the same pattern).
TASK 10.3 Password Generator
Create and run
PS H:\Pooja\day2> notepad password.py
PYTHONpassword.py
import random import string length = input("How long should the password be? ") length = int(length) characters = string.ascii_letters + string.digits + "!@#$%" password = "" for i in range(length): password = password + random.choice(characters) print("Your random password:", password)
  1. Run it and type 12 for the length. You'll get a random 12-character password.
  2. Run it again — you get a different password each time.
  3. This is a useful program. You made something that actually helps in real life!
🌟 Superpower Unlocked

You now know how to create a Python file and run it. That means you can use AI tools (like ChatGPT or Claude) to generate Python code for anything you want — a quiz game, a unit converter, a to-do list — then paste it into a file and run it on your computer. You don't need to understand every line to make it work. This is a genuine superpower. In the coming classes, you'll also learn to write your own complex programs from scratch.


The Big Picture — A Mini Calculator App

Let's look at a program that's a bit more complex. You won't understand every single word yet — and that's completely fine. The goal is to see the big picture of how a real program works. We'll cover every detail starting from the next lecture.

TASK 11.1 Create the Calculator
Create the file
PS H:\Pooja\day2> notepad calculator.py
PYTHONcalculator.py
# =================================== # MY FIRST CALCULATOR # =================================== # --- INPUT SECTION --- # Ask the user for two numbers and an operation print("===== MINI CALCULATOR =====") print() first_number = input("Enter the first number : ") second_number = input("Enter the second number: ") print() print("Choose an operation:") print(" 1 = Add") print(" 2 = Subtract") print(" 3 = Multiply") print(" 4 = Divide") print() choice = input("Your choice (1/2/3/4): ") # --- PROCESS SECTION --- # Convert the text input into actual numbers num1 = float(first_number) num2 = float(second_number) # Perform the chosen operation if choice == "1": result = num1 + num2 operation_name = "Addition" elif choice == "2": result = num1 - num2 operation_name = "Subtraction" elif choice == "3": result = num1 * num2 operation_name = "Multiplication" elif choice == "4": result = num1 / num2 operation_name = "Division" else: result = "Error" operation_name = "Unknown" # --- OUTPUT SECTION --- print() print("===== RESULT =====") print("Operation:", operation_name) print(num1, "and", num2, "=", result) print("===================")
TASK 11.2 Run the Calculator
Running the calculator
PS H:\Pooja\day2> python calculator.py ===== MINI CALCULATOR ===== Enter the first number : 50 Enter the second number: 8 Choose an operation: 1 = Add 2 = Subtract 3 = Multiply 4 = Divide Your choice (1/2/3/4): 3 ===== RESULT ===== Operation: Multiplication 50.0 and 8.0 = 400.0 ===================
  1. Run the calculator. Try all 4 operations.
  2. Try typing 5 for the choice. What happens? (The "else" catches invalid choices.)
  3. Try dividing by zero (0 as the second number, choice 4). What happens?
TASK 11.3 Understanding the Program — Line by Line

Let's read through the code together. You don't need to memorize anything — just build a feeling for how it flows.

📖 Lines Starting with #

Lines that start with # are comments. Python completely ignores them. They're notes for humans reading the code. # Ask the user for two numbers is just a note to help you understand what the next line does.

📖 Variables — Storing Information

first_number = input("Enter the first number : ")

This creates a variable called first_number. A variable is like a labeled box — it has a name (first_number) and holds a value (whatever the user types). The = sign means "store this value in this box." After this line, whenever you write first_number, Python knows you mean whatever the user typed.

📖 float() — Converting Text to Numbers

num1 = float(first_number)

When you type 50, Python actually receives it as the text "50" — not the number 50. Text and numbers are different things in programming. float() converts text into an actual number so we can do math with it. Without this, "50" + "8" would give "508" (joining text) instead of 58 (adding numbers).

📖 if / elif / else — Making Decisions

if choice == "1": means "if the user typed 1, do this."
elif choice == "2": means "otherwise, if they typed 2, do this instead."
else: means "if none of the above matched, do this."

This is how programs make decisions. It's like a flowchart: check the first condition → if no, check the second → if no, check the third → if nothing matches, do the default thing. The == means "is equal to" (two equals signs, not one).

📖 The Big Picture

This program follows the exact Input → Process → Output pattern:

INPUT: Three input() calls get two numbers and an operation choice from the user.
PROCESS: float() converts text to numbers. if/elif/else picks the right math operation. The calculation is done.
OUTPUT: print() shows the result.

Every program you'll ever write follows this same pattern — just with more complexity in each section.

📝 Quiz — Based on the Calculator Code

If the user enters 10, 3, and 2 (for subtract), what will the result be?

A 13.0
B 7.0
C 30.0
D Error
Correct! Choice "2" triggers the subtraction branch: 10.0 - 3.0 = 7.0.
📝 Quiz — Based on the Calculator Code

What does float() do in this program?

A Makes the number a decimal
B Displays the number on screen
C Rounds the number down
D Converts text input into a number so we can do math
Correct! input() always gives us text (like the text "50"), even if the user types a number. float() converts that text into an actual number (50.0) so Python can do math with it.
📝 Quiz — Based on the Calculator Code

The user enters 6, 2, and 7. What will the "Operation" line say?

A Division
B Addition
C Unknown
D The program will crash
Correct! The choice 7 doesn't match "1", "2", "3", or "4", so the else block runs. That sets operation_name to "Unknown" and result to "Error".

Completion Checklist

Check off everything you accomplished today. Look at how much you've done!

🎯 I Can Now…

🏆

You Did Amazing Work Today!

You went from opening a terminal to writing and running real Python programs. You made a calculator. You generated passwords. You taught your computer to count down and launch a rocket. Starting next class, we'll learn Python from the ground up — variables, types, conditions, loops — and you'll understand exactly why everything in today's programs works the way it does.

🚀 What's Next?

In the next lecture we'll start learning Python properly — from the very basics. We'll cover variables, data types, operators, and how Python reads your code line by line. All the pieces from today's calculator (like float(), if/elif/else, ==) will be explained in full detail. You already have a head start — you've seen them in action!