0% found this document useful (0 votes)
2 views8 pages

Introduction to Python Programming

This document provides an introduction to Python, highlighting its features, keywords, identifiers, and data types. It includes practical examples of basic programming concepts such as variables, input/output statements, type casting, and various operators. Additionally, it presents a series of practical exercises to reinforce learning through coding tasks.

Uploaded by

ramavtarsejwal86
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)
2 views8 pages

Introduction to Python Programming

This document provides an introduction to Python, highlighting its features, keywords, identifiers, and data types. It includes practical examples of basic programming concepts such as variables, input/output statements, type casting, and various operators. Additionally, it presents a series of practical exercises to reinforce learning through coding tasks.

Uploaded by

ramavtarsejwal86
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

INTRODUCTION TO PYTHON

Introduction to Python

Python is a high-level, simple and interpreted programming language.


It is easy to learn and widely used in Artificial Intelligence, Data Science, Web Development,
etc.

Features of Python

 Easy to understand and write


 Free and open source
 Interpreted language
 Portable (runs on different systems)
 Large library support

Python Keywords

Keywords are reserved words that have special meaning in Python.


Examples:
if, else, for, while, break, continue, True, False

Identifiers

Identifiers are names given to variables, functions, or objects.

Rules:

 Must start with a letter or underscore


 Cannot start with a number
 Cannot use keywords
 No spaces allowed

Examples:
Valid → a, total, _num
Invalid → 1num, total marks

Variables
Variables are used to store data.

Example:

a = 10
name = "AI"
Data Types in Python
Data Type Example

Int 10

float 5.6

string "Python"

boolean True / False

Input and Output Statements

Input

Used to take input from user.

num = input("Enter a number")

Output

Used to display output.

print(num)

Type Casting
Type casting is converting one data type into another.

Example:

a = int("10")
b = float(5)

Arithmetic Operators

Used to perform mathematical operations.

Operator Meaning

+ Addition

- Subtraction

* Multiplication

/ Division

% Modulus

// Floor Division
Operator Meaning

** Power

Relational Operators
Used to compare values.

Operator Meaning

== Equal

!= Not equal

> Greater than

< Less than

>= Greater than or equal

<= Less than or equal

Logical Operators
Used to combine conditions.

Operator Meaning

and Both conditions true

or Any one true

not Reverse result

Conditional Statements
Used to make decisions.

Example:

if age >= 18:


print("Eligible")
else:
print("Not Eligible")

Comments
Comments are used to explain code.

# This is a comment
Practical 1

Aim: To print your school name


Program:

print("")
Output:

Practical 2

Aim: To add two numbers


Program:

a = 5
b = 3
print(a + b)

Output:

Practical 3

Aim: To find the square of a number


Program:

num = 4
print(num * num)

Output:

16

Practical 4

Aim: To find the area of a rectangle


Program:

length = 10
breadth = 5
area = length * breadth
print(area)

Output:

50

Practical 5

Aim: To find the largest of two numbers


Program:

a = 12
b = 9
if a > b:
print(a)
else:
print(b)

Output:

12

Practical 6

Aim: To print table of 2


Program:

for i in range(1, 11):


print(2 * i)

Output:

2
4
6
8
10
12
14
16
18
20

Practical 7

Aim: To make a simple calculator for addition


Program:

a = 10
b = 5
print("Sum =", a + b)
Output:

Sum = 15

Practical 8

Aim: To print a star pattern


Program:

for i in range(1, 4):


print("*" * i)

Output:

*
**
***

Practical 9

Aim: To check voting eligibility


Program:

age = 16
if age >= 18:
print("Eligible to Vote")
else:
print("Not Eligible to Vote")

Output:

Not Eligible to Vote

Practical 10

Aim: To find simple interest


Program:

p = 1000
r = 5
t = 2
si = (p * r * t) / 100
print(si)

Aim: To calculate total and percentage of two subjects


Program:

m1 = 80
m2 = 90
total = m1 + m2
percentage = total / 2
print(total)
print(percentage)

Practical 11

Aim: To convert days into weeks and days


Program:

days = 10
weeks = days // 7
remaining_days = days % 7
print(weeks)
print(remaining_days)

Output:

1
3

Practical 12

Aim: To find simple interest


Program:

p = 1000
r = 5
t = 2
si = (p * r * t) / 100
print(si)

Output:

100.0

You might also like