Week 1: Python Fundamentals + Git

A 6-day course covering Python basics—variables, data types, input/output, conditionals, arithmetic—plus Git version control.

🧭 Week 1 Concept Map Overview

Click any concept to jump directly to that section!

🖨️ print() 📦 Variables ⌨️ input() 🧮 Arithmetic 🔀 if/else 🔗 and/or/not 🔧 Git

📅 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.

Day 1

Print, Comments, Variables

print(), comments, data types

Day 2

Input, f-strings, Arithmetic

input(), f-strings, operators

Day 3

Conditional Statements

if, elif, else

Day 4

Logical Operators

and, or, not, leap year

Day 5

Mini-Project

Simple Calculator

Day 6

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.

📊 Python Data Types — Visual Guide Infographic

Hover each card to learn more. These are the 4 fundamental data types you'll use every day!

🔤 String str "Hello" 'World'
🔢 Integer int 42, -7, 0
📏 Float float 3.14, -0.5
Boolean bool True / False

The print() Function

day1_print.py
print("Hello, World!")   # displays text
print(42)                # displays an integer
print(3.14)              # displays a float

Comments

day1_comments.py
# 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

day1_variables.py
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)) # 
🏷️ How Variable Assignment Works Visual
name
variable
=
"Alice"
value
str
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.

day1_exercise_solution.py
# 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: Rahul Type: <class 'str'> Age: 14 Type: <class 'int'> Height: 5.2 Type: <class 'float'> Student: True Type: <class 'bool'>
💡 Instructor Tip: Variable names are case-sensitive (nameName) 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

day2_input.py
# 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}")
🎨 Anatomy of an f-string Visual

Hover each part to see what it does!

f " Hello { name } , you scored { marks :.2f } "
f-prefix quotes text braces { } variable format spec

f-strings (Formatted Strings)

day2_fstrings.py
name = "Priya"
marks = 91.567
print(f"{name} scored {marks:.2f} marks.")  # formats to 2 decimal places
# Output: Priya scored 91.57 marks.
🧮 Arithmetic Operators — Quick Reference Infographic

Using a = 10 and b = 3 — hover each card!

+ Addition 10+3 = 13
Subtraction 10-3 = 7
× Multiply 10*3 = 30
÷ Division 10/3 = 3.33
// Floor Div 10//3 = 3
% Modulus 10%3 = 1
** Exponent 10**3 = 1000

Arithmetic Operators

day2_arithmetic.py
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.

day2_exercise_solution.py
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}")
Enter first number: 15 Enter second number: 4 Sum: 15.0 + 4.0 = 19.0 Difference: 15.0 - 4.0 = 11.0 Product: 15.0 * 4.0 = 60.0 Quotient: 15.0 / 4.0 = 3.75
⚠️ Common Mistake: Forgetting to convert 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.

⚖️ Comparison Operators Reference
== equal to
!= not equal
> greater than
< less than
>= greater/equal
<= less/equal
🔀 How if-elif-else Works Flow Diagram
🚀 Start
⬇️
if marks >= 90 ?
✅ True
Grade = "A"
❌ False
elif marks >= 75 ?
⬇️
✅ True
Grade = "B"
❌ False
elif marks >= 60 ?
⬇️
✅ True
Grade = "C"
❌ False
Grade = "D"
⬇️
🏁 End

Only one branch executes — the first condition that's True!

Basic if-else

day3_if_else.py
age = 18
if age >= 18:
    print("You can vote.")
else:
    print("Too young to vote.")

elif (else if) for Multiple Conditions

day3_elif.py
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.

day3_exercise_solution.py
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.")
Enter a number: -7 The number is negative.
💡 Instructor Tip: Show common mistakes like using = (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.

📋 Logical Operators — Truth Tables Infographic
AND (both must be True)
ABA and B
TrueTrueTrue ✅
TrueFalseFalse
FalseTrueFalse
FalseFalseFalse
OR (at least one True)
ABA or B
TrueTrueTrue ✅
TrueFalseTrue ✅
FalseTrueTrue ✅
FalseFalseFalse
NOT (reverses)
Anot A
TrueFalse
FalseTrue ✅

Logical Operators

day4_logical.py
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)
📅 Leap Year Decision Flow Logic Map

Follow the arrows to determine if a year is a leap year:

Divisible by 4? → No → ❌ Not Leap
Divisible by 100? → No → ✅ Leap!
Divisible by 400? → Yes → ✅ Leap! → No → ❌ Not Leap

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

day4_leap_nested.py
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

day4_leap_logical.py
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.")
Enter year: 2024 2024 is a leap year. --- Enter year: 1900 1900 is not a leap year.
💡 Test these years: 1900 (not leap), 2000 (leap), 2024 (leap), 2023 (not leap). Walk through the logic step by step for each.

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

  1. Show a menu: 1. Add   2. Subtract   3. Multiply   4. Divide
  2. Ask user to choose an option.
  3. Ask for two numbers.
  4. Perform the calculation and print the result.
  5. If dividing and second number is 0, print "Error: Cannot divide by zero".
calculator.py
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.")
--- Simple Calculator --- 1. Add 2. Subtract 3. Multiply 4. Divide Choose (1-4): 3 Enter first number: 12 Enter second number: 5 Result: 12.0 * 5.0 = 60.0
🚀 Optional Challenge: Add a loop so the calculator repeats until the user chooses to exit. Wrap the menu in 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.

🔧 Git Workflow — Step by Step Infographic

Your code travels through these stages. Hover each one!

📝 Working Directory Write & edit files
📦 git add Stage changes
💾 git commit Save snapshot
☁️ git push Share remotely

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

CommandPurpose
git initCreate a new repository in the current folder
git statusSee which files have changed
git add <file>Stage a file for commit
git commit -m "message"Save staged changes with a message
git logView 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.

terminal
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
commit a1b2c3d4e5f6... (HEAD -> main) Author: Student Name <student@example.com> Date: Mon Apr 14 10:30:00 2025 +0530 Added calculator project
💡 Tips: Use Git Bash on Windows or Terminal on Mac. Write meaningful commit messages—future you will thank you! Run 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.

Write your solution here.
2. Swap Two Variables

Problem: Input two values. Swap them without a third variable (hint: use tuple unpacking a, b = b, a).

Write your solution here.

⚡ 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.

Write your solution here.
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".

Write your solution here.