0% found this document useful (0 votes)
1 views23 pages

Python Programming 1

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

Python Programming 1

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 23

INTRODUCTION TO PYTHON

PROGRAMMING
…..BY FARHANA ZAINAB SADIA
Questions:

•Have you ever heard of programming?


•Where do you think coding is used?

• Python Explained for Kids | What is Python Coding La


nguage? | Why Python is So Popular?
• What is Python? | Python for Kids | Python Coding for
Kids | Coding for Kids | Kids Coding | Coding
WHAT IS PYTHON?

• Python is a popular programming language


• Used in games, websites, robotics, and more
• Real-world examples:
• Instagram: Backend is built using Python
• Google: Uses Python for many internal systems
• YouTube: Originally developed using Python
• Netflix: Uses Python for data analysis and automation
• NASA: Uses Python for scientific programming and research
GREAT FOR BEGINNERS
Because:

•It has simple and easy-to-read syntax

•Fewer lines of code are needed to do basic tasks

•It is very readable—almost like English

•Widely supported with tutorials and community help


A SHORT HISTORY OF PYTHON

• Created by Guido van Rossum in 1989


• First released in 1991
• Named after the comedy group "Monty Python"
• Focuses on code readability and simplicity
PYTHON ENVIRONMENT
• Tools: IDLE, Replit, Trinket
• Syntax: The set of rules that defines how Python code should be
written
• Comments: A line in code that is ignored by the computer, used to
explain what the code does (starts with #)
• Quotation: Used to wrap text in a print statement; they must be
straight (" or ') and match correctly
• Spaces used at the beginning of a line to show which code belongs to a
block (e.g., under if, for, def). Python requires correct indentation to
run code properly
DEMO – LET’S CODE TOGETHER

• print("Hello, World!")
• # Print a welcome message
• print("Hello, welcome to your first Python class!")

• # Let's store your name in a variable


• name = input("What's your name? ")

• # Now we greet you using the name


• print("Nice to meet you, " + name + "!")
VARIABLES IN PYTHON
• A variable is a name we give to a value in our program so we
can store and use it later.
• Why use variables? They help store data for later use.
• Rules for naming variables:
-Must start with a letter or underscore.
-Can contain letters, numbers, and underscores.
- Case sensitive
- Cannot be python keywords. (For example: if, while)
EXAMPLE OF VARIABLE

• name = "Alice"
• age = 13
• height = 1.56
• print(name)
• print(age)
• print(height)
CLASSWORK

• Create 2 variables: one for your name, one for your favourite
subject, and print them.
DATA TYPES IN PYTHON

•String (str): Text, inside quotes → "Hello“

•Integer (int): Whole number → 25

•Float (float): Decimal number → 3.14

•Boolean (bool): True/False values


EXAMPLE OF DATA TYPES

• name = "Ali" # string


• age = 14 # integer
• height = 1.65 # float
• is_student = True # boolean

• print(type(name))
• print(type(age))
• print(type(height))
• print(type(is_student))
ARITHMETIC OPERATORS IN PYTHON

•+ Addition

•- Subtraction

•* Multiplication

•/ Division (float result)

•// Floor Division (whole number result)

•% Modulus (remainder)

•** Exponent (power)


EXAMPLE:

• x = 10
•y=3
• print(x + y)
• print(x - y)
• print(x * y)
• print(x / y)
CLASSWORK

•Create two integer variables: num1 and num2.


•Perform addition, subtraction, multiplication, and division.
•Display the results with clear labels.
• # Simple math with Python
• print("Let's do a little math.")
• num1 = 1
• num2 = 2
• sum = num1 + num2
• # Display the result
• print("The sum of the numbers is:", sum)
• # Simple math with Python
• print("Let's do a little math.")
• num1 = int(input("Enter a number: "))
• num2 = int(input("Enter another number: "))
• sum = num1 + num2

• # Display the result


• print("The sum of your numbers is:", sum)
PRACTICE:

• name = "Alice"
• age = 13
• height = 4.9

• print("Name:", name)
• print("Age:", age)
• print("Height:", height)
Practice Task 1:

•Create variables: student_name, grade, and percentage.


•Print them in a sentence.

•Write a program that takes two numbers (x and y) and prints their
sum, difference, product, quotient, and modulus.
INPUT IN PYTHON

• input() is used to get data from the user.


• Always returns a string, so we convert using int() or float().
• Example:
• name = input("Enter your name: ")
• age = int(input("Enter your age: "))
• print("Hello", name, "you are", age, "years old!")
PRACTICE TASK 2:

• Ask the user to enter two numbers.


• Calculate and display their sum, product, and modulus.
CASTING

• Casting = converting one data type to another.


• Functions: int(), float(), str()
• Example:
• x = "5"
• y = int(x) + 10
• print("Result:", y)
PRACTICE TASK 3:

• Take a number as string input (e.g., "20") and convert it to


integer.
• Multiply by 2 and print the result.

You might also like