1. What is Python?
Python is a programming language. A programming language is a way to give instructions to a computer. You write clear commands, and the computer follows them.
Think of Python as a very obedient student. It does not guess much. It does exactly what you write. If you write correct instructions, Python gives correct results. If you write unclear instructions, Python complains with an error.
Today’s Skills
- Display messages using
print() - Take user input using
input() - Store values in variables
- Convert text into numbers
- Do addition, subtraction, multiplication and division
- Build tiny useful programs
2. Making Python Speak with print()
The first command most learners use in Python is print().
It displays something on the screen.
print("Hello, Python!")
How it works
| Part | Meaning |
|---|---|
print |
The command that displays output |
() |
Parentheses hold the thing we want to print |
"Hello, Python!" |
Text written inside quotes |
Print more than one thing
print("My name is Champak.")
print("I am learning Python.")
print("Python is useful.")
I am learning Python.
Python is useful.
Printing numbers
Text needs quotes. Numbers do not need quotes.
print(10)
print(25)
print(100)
Printing text and numbers together
print("Age:", 25)
print("Tea cups:", 4)
print("Price:", 40)
Tea cups: 4
Price: 40
print() help you print
many things together.
Print your name, your city, and one thing you want to learn in Python.
print("My name is _____")
print("I live in _____")
print("I want to learn _____")
3. Variables: Small Boxes for Data
A variable is like a named box. You can store something inside it and use it later.
name = "Amit"
age = 15
print(name)
print(age)
15
Better output
name = "Amit"
age = 15
print("Name:", name)
print("Age:", age)
Age: 15
Good variable names
| Good | Not Good | Reason |
|---|---|---|
student_name |
s |
Clear names are easier to understand |
total_marks |
tm |
Full meaning is visible |
tea_price |
tp |
Readable code is better code |
4. Taking User Input with input()
input() lets Python ask a question and wait for the user to type an answer.
name = input("What is your name? ")
print("Welcome,", name)
Welcome, Ravi
Make it feel like a conversation
name = input("Enter your name: ")
city = input("Enter your city: ")
print("Hello", name)
print("You are from", city)
print("Welcome to Python class!")
Very important: input() gives text
Whatever comes from input() is treated as text first, even if the user types a number.
age = input("Enter your age: ")
print(age)
Here age looks like a number, but Python stores it as text.
This matters when we want to calculate.
5. Simple Calculations in Python
Python can work like a calculator.
print(10 + 5)
print(10 - 5)
print(10 * 5)
print(10 / 5)
print(2 ** 3)
print(10 % 3)
Calculation with variables
price = 10
quantity = 5
total = price * quantity
print("Total bill:", total)
The common beginner mistake
Look at this program:
a = input("Enter first number: ")
b = input("Enter second number: ")
print(a + b)
If the user enters 10 and 20, the output will be:
Why? Because input() gives text. Python joins the text instead of adding numbers.
The solution: convert text into numbers
Use int() for whole numbers.
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
sum_result = a + b
print("Sum:", sum_result)
Enter second number: 20
Sum: 30
Use float() for decimal numbers
float() is used for numbers with decimal points.
length = float(input("Enter length: "))
width = float(input("Enter width: "))
area = length * width
print("Area:", area)
Enter width: 2
Area: 11.0
6. Mini Projects
Now let us make tiny useful programs. These are small, but they teach the real habit of programming: input, process, output.
Project 1: Tea Shop Bill Calculator
customer_name = input("Enter customer name: ")
cups = int(input("How many cups of tea? "))
price_per_cup = 10
total = cups * price_per_cup
print("Customer:", customer_name)
print("Cups:", cups)
print("Total bill: Rs.", total)
Project 2: Simple Marks Calculator
name = input("Enter student name: ")
maths = int(input("Enter Maths marks: "))
science = int(input("Enter Science marks: "))
english = int(input("Enter English marks: "))
total = maths + science + english
average = total / 3
print("Student:", name)
print("Total marks:", total)
print("Average marks:", average)
Project 3: Age Calculator
name = input("Enter your name: ")
birth_year = int(input("Enter your birth year: "))
current_year = int(input("Enter current year: "))
age = current_year - birth_year
print("Hello", name)
print("Your age is approximately", age)
Project 4: Rectangle Area Calculator
length = float(input("Enter rectangle length: "))
width = float(input("Enter rectangle width: "))
area = length * width
print("Area of rectangle:", area)
Project 5: Your First Friendly Assistant
name = input("What is your name? ")
city = input("Which city are you from? ")
goal = input("What do you want to learn? ")
print("Hello", name)
print("Nice to meet someone from", city)
print("Your learning goal is:", goal)
print("Keep practicing. Python will become easy!")
7. Input, Process, Output
Most beginner programs follow this simple pattern:
Input
Take information from the user.
cups = int(input("Cups: "))
Process
Calculate or prepare the result.
total = cups * 10
Output
Show the answer.
print("Bill:", total)
8. Common Errors and Fixes
| Error | Wrong Code | Correct Code |
|---|---|---|
| Missing quotes around text | print(Hello) |
print("Hello") |
| Using input number without conversion | age = input("Age: ") |
age = int(input("Age: ")) |
| Wrong multiplication symbol | total = price x qty |
total = price * qty |
| Wrong variable spelling | print(nmae) |
print(name) |
9. Practice Questions
Ask the user for their name and print a welcome message.
Ask the user for two numbers and print their sum.
Ask the user for the price of one notebook and the number of notebooks. Print the total cost.
Ask for marks in 5 subjects. Print total marks and average marks.
Ask for distance and time. Print speed using this formula: speed = distance / time.
10. Practice in the Python Editor
Type the examples below in the editor. Start small. First run print().
Then run input(). Then create a calculator.
11. Quick Quiz
Show Answer
print()
Show Answer
input()
print(5 + 3)
Show Answer
8
Show Answer
Because input() gives text. int() converts that text into a whole number.
a = "10"
b = "20"
print(a + b)
Show Answer
1020, because both values are text.
12. Final Challenge
Make a complete small program called My First Python Bill Maker.
Your program should:
- Ask the customer name
- Ask the item name
- Ask the item price
- Ask the quantity
- Calculate the total bill
- Print a clean bill
customer = input("Enter customer name: ")
item = input("Enter item name: ")
price = float(input("Enter item price: "))
quantity = int(input("Enter quantity: "))
total = price * quantity
print("---------------------")
print("BILL")
print("---------------------")
print("Customer:", customer)
print("Item:", item)
print("Price:", price)
print("Quantity:", quantity)
print("Total: Rs.", total)
print("---------------------")
print("Thank you!")