University Course • EduArtha
Python Programming
Master Python from scratch — variables, control flow, functions, OOP, file handling, and regular expressions. Includes 15 complete lab experiments with solutions.
📚 6 Units | 14 Chapters | 15 Lab Programs | Complete Solutions
Setting Up Your Programming Environment
Python installation, variables, expressions & statements
Setting Up & Hello World
Learning Objectives
- Understand Python versions and choose the right one
- Install Python on Windows and configure PATH
- Write and run your first Python program
- Use IDLE, VS Code, and the command line
- Master the print() and input() functions
1.1 What is Python?
Python is a high-level, interpreted, general-purpose programming language created by Guido van Rossum in 1991. It emphasizes code readability with its clean syntax and indentation-based block structure. Python is used everywhere — web development (Django, Flask), data science (NumPy, Pandas), AI/ML (TensorFlow, PyTorch), automation, and more.
1.2 Python 2 vs Python 3
| Feature | Python 2 | Python 3 |
|---|---|---|
print "hello" (statement) | print("hello") (function) | |
| Integer Division | 5/2 = 2 | 5/2 = 2.5 |
| Unicode | ASCII by default | Unicode by default |
| Input | raw_input() | input() |
| Status | End of Life (Jan 2020) | Use this! |
Always Use Python 3
Python 2 reached End of Life on January 1, 2020. All new projects should use Python 3.x. As of 2025, the latest stable version is Python 3.12+.
1.3 Installing Python on Windows
Step-by-Step Installation
- Go to
https://www.python.org/downloads/ - Click "Download Python 3.12.x" (latest stable)
- IMPORTANT: Check ✅ "Add Python to PATH" on the installer
- Click "Install Now" (default settings are fine)
- Verify: open Command Prompt, type
python --version
Command Prompt
# Verify Python installation
C:\> python --version
Python 3.12.4
# Verify pip (package installer)
C:\> pip --version
pip 24.0 from C:\Python312\Lib\site-packages\pip (python 3.12)
1.4 Your First Python Program
Create a file called hello.py and type:
Python
# hello.py — Your first Python program!
print("Hello, World!")
Run it from the terminal:
Command Prompt
C:\projects> python hello.py
Hello, World!
1.5 Ways to Run Python
| Method | Best For | How |
|---|---|---|
| IDLE | Quick testing, beginners | Comes with Python, search "IDLE" in Start |
| VS Code | Real projects, debugging | Install Python extension, press F5 to run |
| Command Line | Scripts, automation | python filename.py |
| Interactive Mode | Quick experiments | Type python in terminal → type code |
| Jupyter Notebook | Data science, learning | pip install jupyter → jupyter notebook |
1.6 The print() Function
Python
# Basic printing
print("Hello, World!") # String
print(42) # Number
print(3.14) # Float
print(True) # Boolean
# Multiple values
print("Name:", "Alice", "Age:", 25)
# Output: Name: Alice Age: 25
# Custom separator and end
print("A", "B", "C", sep="-") # Output: A-B-C
print("Hello", end=" ") # No newline at end
print("World") # Output: Hello World
# Escape characters
print("Line1\nLine2") # Newline
print("Tab\there") # Tab
print("She said \"hi\"") # Escaped quotes
1.7 The input() Function
Python
# Get user input
name = input("What is your name? ")
print("Hello,", name)
# input() always returns a string!
age_str = input("Enter your age: ") # Returns "25" (a string)
age = int(age_str) # Convert to integer
print("Next year you'll be", age + 1)
# Shortcut: convert inline
num = int(input("Enter a number: "))
print("Double:", num * 2)
Exercises
Exercise 1.1: Write a program that asks for the user's name and age, then prints a greeting
Python
name = input("Enter your name: ")
age = int(input("Enter your age: "))
print(f"Hello {name}! You are {age} years old.")
print(f"In 5 years, you'll be {age + 5}.")
Exercise 1.2: Write a program to calculate the area of a rectangle
Python
length = float(input("Enter length: "))
width = float(input("Enter width: "))
area = length * width
perimeter = 2 * (length + width)
print(f"Area = {area}")
print(f"Perimeter = {perimeter}")
Industry Application: Automated Server Health Check Script
At companies like AWS, Google Cloud, and Azure, DevOps engineers write Python scripts to perform automated server health checks. These scripts run periodically (via cron jobs) to verify system status, Python environment, and uptime — printing critical diagnostics to monitoring dashboards.
Python
import platform
import sys
import os
from datetime import datetime
# Automated Server Health Check Script
print("═" * 50)
print("🖥️ SERVER HEALTH CHECK REPORT")
print("═" * 50)
print(f"Python Version : {sys.version.split()[0]}")
print(f"OS : {platform.system()} {platform.release()}")
print(f"Machine : {platform.machine()}")
print(f"Hostname : {platform.node()}")
print(f"Timestamp : {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
print(f"CPU Count : {os.cpu_count()}")
print("═" * 50)
print("✅ Status: All systems operational")
Quick Quiz — Chapter 1
Q1. Who created the Python programming language?
- James Gosling
- Guido van Rossum
- Dennis Ritchie
- Bjarne Stroustrup
Q2. What is the correct syntax for printing "Hello" in Python 3?
- echo "Hello"
- print("Hello")
- printf("Hello")
- console.log("Hello")
Q3. What data type does the input() function always return?
- int
- float
- str
- bool
Q4. Python is an _______ language, meaning code is executed line by line.
- compiled
- interpreted
- assembled
- machine-level
Q5. What is the default file extension for Python scripts?
- .pt
- .py
- .python
- .pn
Chapter Summary
- Python 3 is the current standard — always use Python 3.x
- Always check "Add to PATH" when installing on Windows
print()outputs to the console,input()reads from the userinput()always returns a string — useint()orfloat()to convert- Use IDLE for quick tests, VS Code for real projects