0% found this document useful (0 votes)
3 views11 pages

Lecture 1 - Python

This document provides an introduction to Python programming, covering the basics of programming, the Python language, and its features. It includes examples of simple Python programs, the use of the print() function, and basic calculations, along with practice exercises for students. By the end of the session, students will have a foundational understanding of programming concepts and be able to write basic Python programs.

Uploaded by

muditshah02012
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views11 pages

Lecture 1 - Python

This document provides an introduction to Python programming, covering the basics of programming, the Python language, and its features. It includes examples of simple Python programs, the use of the print() function, and basic calculations, along with practice exercises for students. By the end of the session, students will have a foundational understanding of programming concepts and be able to write basic Python programs.

Uploaded by

muditshah02012
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

SESSION 1 – INTRODUCTION TO PYTHON

Session Objective
By the end of this session, students will:

 Understand what programming is


 Understand what Python is and why it is used
 Know the basic structure of a Python program
 Use the print() function
 Write simple Python programs

What is Programming?
Definition

Programming is the process of giving step-by-step instructions to a computer to perform a specific task.

A computer is a machine.
It cannot think on its own.
It only follows the instructions that are given to it.

These instructions written in a programming language are called a program.

Real-Life Example

Suppose you want to make tea.

Steps:

1. Turn on the gas


2. Add water
3. Add tea leaves
4. Add milk
5. Add sugar
6. Boil

These steps are instructions.

Similarly, in programming, we give step-by-step instructions to the computer to complete a task.

What is a Programming Language?


Computers understand only binary language (0 and 1).

But humans cannot easily write programs in binary form.

So, programming languages were created, such as:


 C
 C++
 Java
 Python
 JavaScript

These languages are closer to English and easier for humans to understand.

What is Python?
Python is a high-level programming language.

It was created by Guido van Rossum in 1991.

Python is:

 Simple
 Easy to read
 Beginner-friendly
 Powerful

Features of Python
1️Simple and Easy to Learn: Python syntax is easy to understand.

Example:

print("Hello")

2️Readable Language: Python code looks similar to English.

3️Cross-Platform: Python works on Windows, Mac, and Linux.

4️Free and Open Source: Anyone can download and use Python for free.

5️Large Community Support: Millions of developers use Python worldwide.

Uses of Python
Python is used in:

 Web development
 Data science
 Machine learning
 Artificial Intelligence
 Game development
 Automation
 Software development
 School projects
Basic Structure of a Python Program
A simple Python program looks like this:

print("Hello World")

Here:

 print() is a function
 It displays output on the screen
 "Hello World" is a string (text)

First Python Program


print("Hello World")

Output:
Hello World

Printing Multiple Lines


print("My Name is Jay")
print("I am learning Python")
print("Programming is interesting")

Output:
My Name is Jay
I am learning Python
Programming is interesting

New Line Character (\n)


print("Python\nis\nEasy")

Output:
Python
is
Easy

Tab Space (\t)


print("Name\tAge\tCity")

Output:
Name Age City
Simple Calculations in Python
print(10 + 5)
print(20 - 8)
print(6 * 4)
print(20 / 5)

Output:
15
12
24
4.0

Introduction to Variables
A variable is a container used to store data.

Example:

name = "Riya"
age = 14
print(name)
print(age)

Output:
Riya
14

SOLVED EXAMPLES

Example 1
Question: Write a Python program to display the following message:

Welcome to Python Programming


This is my first coding class
I am ready to learn

Program
print("Welcome to Python Programming")
print("This is my first coding class")
print("I am ready to learn")
Output
Welcome to Python Programming
This is my first coding class
I am ready to learn
Explanation

Each print() statement displays one line.


Example 2
Question: Write a program to display a student's name, class, and school name on separate lines.

Program
print("Student Name: Aarav")
print("Class: 8A")
print("School: Macro Vision Academy")

Output
Student Name: Aarav
Class: 8A
School: Macro Vision Academy

Example 3
Question: Write a program to store two numbers in variables and print their sum.

Program
a = 25
b = 15
print("Sum is:", a + b)

Output
Sum is: 40

PRACTICE SECTION – DETAILED QUESTIONS WITH SOLUTIONS

Practice Program 1
Detailed Question:

Write a Python program to display your complete personal introduction.


The program should clearly display the following details on separate lines:

 Your Full Name


 Your Class
 Your Section
 Your School Name
 Your City
 Your Hobby

Make sure each piece of information appears on a new line with proper labeling.

Program:
print("Full Name: Jay Khatri")
print("Class: 8")
print("Section: A")
print("School: Macro Vision Academy")
print("City: Indore")
print("Hobby: Reading Books")

Output:
Full Name: Jay Khatri
Class: 8
Section: A
School: Macro Vision Academy
City: Indore
Hobby: Reading Books

Practice Program 2
Detailed Question:

Write a Python program to create a formatted Student Identity Card.


The output should look like a proper ID card enclosed within lines.
It must contain:

 A heading "Student Identity Card"


 Student Name
 Class
 Section
 Roll Number
 School Name

Use decorative lines before and after the card to make it look structured.

Program:
print("=================================")
print(" Student Identity Card ")
print("=================================")
print("Name: Riya Sharma")
print("Class: 7")
print("Section: B")
print("Roll Number: 23")
print("School: Macro Vision Academy")
print("=================================")

Output:
=================================
Student Identity Card
=================================
Name: Riya Sharma
Class: 7
Section: B
Roll Number: 23
School: Macro Vision Academy
=================================
Practice Program 3
Detailed Question:

Write a Python program to display a properly formatted shopping bill header for a grocery store.

The program should display:

 Store Name
 City
 A blank line
 A table header with columns: Item Name and Price
 At least three grocery items with their prices

Use tab spacing to align the columns neatly.

Program:
print("ABC Super Market")
print("Indore\n")
print("Item Name\tPrice")
print("Rice\t\t50")
print("Sugar\t\t40")
print("Oil\t\t120")

Output:
ABC Super Market
Indore

Item Name Price


Rice 50
Sugar 40
Oil 120

Practice Program 4
Detailed Question:

Write a Python program that calculates and displays:

 The square of the number 9


 The cube of the number 9

Display the result with proper labels so that the output clearly shows what value is being calculated.

Program:
print("Square of 9:", 9 * 9)
print("Cube of 9:", 9 * 9 * 9)

Output:
Square of 9: 81
Cube of 9: 729

Practice Program 5
Detailed Question:

Write a Python program to print a 5 × 5 square pattern using stars (*).


Each row should contain exactly 5 stars.

Program:
print("*****")
print("*****")
print("*****")
print("*****")
print("*****")

Output:
*****
*****
*****
*****
*****

Practice Program 6
Detailed Question:

Write a Python program to display a right-angled triangle pattern of stars with 5 rows.

Each row should increase by one star.

Program:
print("*")
print("**")
print("***")
print("****")
print("*****")

Output:
*
**
***
****
*****

Practice Program 7
Detailed Question:

Write a Python program to display a student's marks report.

The report must include:

 A heading "Marks Report"


 Marks in five subjects
 Each subject should appear on a new line

Program:
print("Marks Report")
print("English: 85")
print("Maths: 92")
print("Science: 88")
print("Hindi: 78")
print("Social Science: 81")

Output:
Marks Report
English: 85
Maths: 92
Science: 88
Hindi: 78
Social Science: 81

Practice Program 8
Detailed Question:

Write a Python program to display the multiplication table of 6 from 1 to 5.

Each line should clearly show the format:


6x1=6

Program:
print("Multiplication Table of 6")
print("6 x 1 = 6")
print("6 x 2 = 12")
print("6 x 3 = 18")
print("6 x 4 = 24")
print("6 x 5 = 30")
Output:
Multiplication Table of 6
6 x 1 = 6
6 x 2 = 12
6 x 3 = 18
6 x 4 = 24
6 x 5 = 30

Practice Program 9
Detailed Question:

Write a Python program to display a weekly timetable in table format using tab spacing.

The table must contain:

 Day
 Subject 1
 Subject 2

Include at least two rows of data.

Program:
print("Day\tSubject 1\tSubject 2")
print("Monday\tMaths\t\tScience")
print("Tuesday\tEnglish\t\tSST")

Output:
Day Subject 1 Subject 2
Monday Maths Science
Tuesday English SST

Practice Program 10
Detailed Question:

Write a Python program to display a motivational banner using stars around the message:

"Never Give Up"

The message should appear centered between star lines.

Program:
print("***********************")
print("* Never Give Up *")
print("***********************")

Output:
***********************
* Never Give Up *
***********************

SESSION OUTCOME
After completing this session, students:

 Understand programming basics


 Understand what Python is
 Can write simple Python programs
 Can use print() function
 Can perform basic calculations
 Have a basic understanding of variables

You might also like