Week 1: Python Fundamentals + Git
A 6-day course covering Python basics—variables, data types, input/output, conditionals, arithmetic—plus Git version control.
Click any concept to jump directly to that section!
📅 Overview: Days 1–5 cover Python fundamentals with hands-on exercises. Day 6 introduces Git for version control. Each day includes concept explanations, live coding demos, student exercises, and solution discussions.
🎯 Goal: By the end of this week, you'll write Python scripts, handle user input, make decisions with conditionals, and track your code with Git.
Print, Comments, Variables
print(), comments, data types
Input, f-strings, Arithmetic
input(), f-strings, operators
Conditional Statements
if, elif, else
Logical Operators
and, or, not, leap year
Mini-Project
Simple Calculator
Git Basics
init, add, commit, log
Day 1 Print, Comments, Variables & Data Types
Learning Objectives: Understand what a program is. Use print() to display output. Write single-line and multi-line comments. Create variables to store different types of data. Identify basic data types: int, float, str, bool.
Hover each card to learn more. These are the 4 fundamental data types you'll use every day!
The print() Function
print("Hello, World!") # displays text
print(42) # displays an integer
print(3.14) # displays a float
Comments
# This is a single-line comment
print("Python is fun") # comment after code
"""
This is a multi-line comment (or docstring).
It can span multiple lines.
Use triple quotes to create it.
"""
Variables & Data Types
name = "Alice" # str (string)
age = 15 # int (integer)
height = 5.6 # float (decimal)
is_student = True # bool (boolean)
# Check types with type()
print(type(name)) #
print(type(age)) #
print(type(height)) #
print(type(is_student)) #
variable
value
type
Python figures out the type automatically — no need to declare it!
🧑💻 Exercise: Student Info
Create variables for your name, age, height, and whether you are a student. Print each variable along with its data type.
# Student info
name = "Rahul"
age = 14
height = 5.2
is_student = True
# Print with type
print("Name:", name, "Type:", type(name))
print("Age:", age, "Type:", type(age))
print("Height:", height, "Type:", type(height))
print("Student:", is_student, "Type:", type(is_student))
name ≠ Name) and cannot start with a number. Use meaningful, descriptive names.Day 2 Input/Output, f-strings & Arithmetic Operators
Learning Objectives: Take user input with input(). Convert strings to numbers (int(), float()). Use f-strings for formatted output. Perform arithmetic: + - * / // % **.
Input and Type Conversion
# input() always returns a string
name = input("Enter your name: ")
# Convert to numbers for calculations
age = int(input("Enter your age: "))
height = float(input("Enter your height: "))
print(f"Hello {name}, age {age}, height {height}")
Hover each part to see what it does!
f-strings (Formatted Strings)
name = "Priya"
marks = 91.567
print(f"{name} scored {marks:.2f} marks.") # formats to 2 decimal places
# Output: Priya scored 91.57 marks.
Using a = 10 and b = 3 — hover each card!
Arithmetic Operators
a = 10
b = 3
print(a + b) # 13 (addition)
print(a - b) # 7 (subtraction)
print(a * b) # 30 (multiplication)
print(a / b) # 3.333... (float division)
print(a // b) # 3 (floor division)
print(a % b) # 1 (remainder / modulus)
print(a ** b) # 1000 (exponent: 10^3)
🧑💻 Exercise: Two-Number Calculator
Ask the user for two numbers. Print their sum, difference, product, and quotient using f-strings.
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
sum_result = num1 + num2
diff_result = num1 - num2
prod_result = num1 * num2
quot_result = num1 / num2
print(f"Sum: {num1} + {num2} = {sum_result}")
print(f"Difference: {num1} - {num2} = {diff_result}")
print(f"Product: {num1} * {num2} = {prod_result}")
print(f"Quotient: {num1} / {num2} = {quot_result:.2f}")
input() with int() or float(). Without conversion, + will concatenate strings instead of adding numbers!Day 3 Conditional Statements (if, elif, else)
Learning Objectives: Use if, elif, else to make decisions. Write comparison operators: == != > < >= <=. Combine conditions with and, or, not.
Only one branch executes — the first condition that's True!
Basic if-else
age = 18
if age >= 18:
print("You can vote.")
else:
print("Too young to vote.")
elif (else if) for Multiple Conditions
marks = 85
if marks >= 90:
grade = "A"
elif marks >= 75:
grade = "B"
elif marks >= 60:
grade = "C"
else:
grade = "D"
print(f"Grade: {grade}")
🧑💻 Exercise: Positive, Negative, or Zero
Write a program that asks for a number and tells whether it is positive, negative, or zero.
num = float(input("Enter a number: "))
if num > 0:
print("The number is positive.")
elif num < 0:
print("The number is negative.")
else:
print("The number is zero.")
= (assignment) instead of == (comparison) in conditions. This is the #1 beginner bug!Day 4 Logical Operators & Nested if (Leap Year)
Learning Objectives: Use logical operators (and, or, not). Write nested if statements. Solve the classic leap year problem.
| AND (both must be True) | ||
|---|---|---|
| A | B | A and B |
| True | True | True ✅ |
| True | False | False |
| False | True | False |
| False | False | False |
| OR (at least one True) | ||
|---|---|---|
| A | B | A or B |
| True | True | True ✅ |
| True | False | True ✅ |
| False | True | True ✅ |
| False | False | False |
| NOT (reverses) | |
|---|---|
| A | not A |
| True | False |
| False | True ✅ |
Logical Operators
x = 10
print(x > 5 and x < 20) # True (both must be True)
print(x < 5 or x > 8) # True (at least one True)
print(not x == 10) # False (reverses the result)
Follow the arrows to determine if a year is a leap year:
Test: 2000 ✅ | 1900 ❌ | 2024 ✅ | 2023 ❌
Leap Year Rules
A year is a leap year if:
✅ It is divisible by 4 AND
✅ (It is NOT divisible by 100 OR it is divisible by 400)
Nested if Approach
year = 2024
if year % 4 == 0:
if year % 100 == 0:
if year % 400 == 0:
print("Leap year")
else:
print("Not a leap year")
else:
print("Leap year")
else:
print("Not a leap year")
Simpler: Logical Operators Approach
year = int(input("Enter year: "))
if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):
print(f"{year} is a leap year.")
else:
print(f"{year} is not a leap year.")
Day 5 Mini-Project: Simple Calculator
Learning Objectives: Combine everything learned—variables, input, conditionals, arithmetic. Handle division by zero. Build a menu-driven program.
Project Requirements
- Show a menu: 1. Add 2. Subtract 3. Multiply 4. Divide
- Ask user to choose an option.
- Ask for two numbers.
- Perform the calculation and print the result.
- If dividing and second number is 0, print "Error: Cannot divide by zero".
print("--- Simple Calculator ---")
print("1. Add")
print("2. Subtract")
print("3. Multiply")
print("4. Divide")
choice = input("Choose (1-4): ")
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
if choice == '1':
result = num1 + num2
print(f"Result: {num1} + {num2} = {result}")
elif choice == '2':
result = num1 - num2
print(f"Result: {num1} - {num2} = {result}")
elif choice == '3':
result = num1 * num2
print(f"Result: {num1} * {num2} = {result}")
elif choice == '4':
if num2 != 0:
result = num1 / num2
print(f"Result: {num1} / {num2} = {result}")
else:
print("Error: Cannot divide by zero.")
else:
print("Invalid choice.")
while True: and add a "5. Exit" option.Day 6 Git: Version Control Basics
Learning Objectives: Understand why we use Git. Install Git. Initialize a repository. Stage and commit changes. Check status and log.
Your code travels through these stages. Hover each one!
What is Git?
Git is a version control system that tracks changes in files. It lets you go back to previous versions and is essential for collaboration.
Basic Git Commands
| Command | Purpose |
|---|---|
git init | Create a new repository in the current folder |
git status | See which files have changed |
git add <file> | Stage a file for commit |
git commit -m "message" | Save staged changes with a message |
git log | View commit history |
🧑💻 Exercise: Create Your First Git Repo
Task: Create a folder python-week1, add your calculator code, initialize Git, and make your first commit.
mkdir python-week1
cd python-week1
# Create calculator.py using any text editor (copy code from Day 5)
git init
git add calculator.py
git commit -m "Added calculator project"
git log
git status often to understand what's happening.Week 1 Practice Problems
Test your understanding with these problems covering all Week 1 concepts.
🔰 Beginner Level
1. Age in Days Calculator
Problem: Ask the user for their age in years. Convert it to days (ignore leap years) and print the result.
age_years = int(input("Enter your age in years: "))
age_days = age_years * 365
print(f"You are approximately {age_days} days old.")2. Even or Odd Checker
Problem: Ask for an integer and print whether it is even or odd using the modulo operator.
num = int(input("Enter an integer: "))
if num % 2 == 0:
print(f"{num} is even.")
else:
print(f"{num} is odd.")3. Grading System
Problem: Accept marks (0–100) and assign a grade: A (90+), B (75–89), C (60–74), D (below 60).
marks = float(input("Enter marks (0-100): "))
if marks >= 90:
grade = "A"
elif marks >= 75:
grade = "B"
elif marks >= 60:
grade = "C"
else:
grade = "D"
print(f"Grade: {grade}")⚡ Intermediate Level
4. Triangle Type Checker
Problem: Input three side lengths. Determine if the triangle is equilateral, isosceles, or scalene. Bonus: check if it's a valid triangle first.
a = float(input("Side 1: "))
b = float(input("Side 2: "))
c = float(input("Side 3: "))
if a + b > c and b + c > a and c + a > b:
if a == b == c:
print("Equilateral triangle")
elif a == b or b == c or c == a:
print("Isosceles triangle")
else:
print("Scalene triangle")
else:
print("Not a valid triangle.")5. Enhanced Calculator with Modulo & Exponent
Problem: Extend the Day 5 calculator to also support modulo (%) and exponent (**) operations.
print("--- Enhanced Calculator ---")
print("1. Add 2. Subtract 3. Multiply")
print("4. Divide 5. Modulo 6. Exponent")
choice = input("Choose (1-6): ")
n1 = float(input("First number: "))
n2 = float(input("Second number: "))
if choice == '5':
print(f"Result: {n1} % {n2} = {n1 % n2}")
elif choice == '6':
print(f"Result: {n1} ** {n2} = {n1 ** n2}")
elif choice == '4':
print(f"Result: {n1} / {n2} = {n1 / n2}" if n2 != 0 else "Error: Division by zero")
elif choice == '1':
print(f"Result: {n1} + {n2} = {n1 + n2}")
elif choice == '2':
print(f"Result: {n1} - {n2} = {n1 - n2}")
elif choice == '3':
print(f"Result: {n1} * {n2} = {n1 * n2}")
else:
print("Invalid choice.")Unsolved Exercises
Challenge yourself! Try these without peeking at solutions. All concepts are from Week 1.
🔰 Beginner
1. Celsius to Fahrenheit Converter
Problem: Read Celsius from the user and convert to Fahrenheit: F = (C × 9/5) + 32. Print rounded to 1 decimal.
2. Swap Two Variables
Problem: Input two values. Swap them without a third variable (hint: use tuple unpacking a, b = b, a).
⚡ Intermediate
3. Bill Splitter with Tip
Problem: Input bill amount, tip %, and number of people. Calculate total (bill + tip) and split equally. Round to 2 decimals.
4. Password Strength Checker
Problem: Ask for a password string. Print "Strong" if length ≥ 8 AND contains at least one digit (hint: use any(char.isdigit() for char in password)), otherwise "Weak".