0% found this document useful (0 votes)
0 views

python-practicals (1)

The document outlines three Python programming practicals: Keywords Program, Operator Program, and Control Statement Program. Each practical includes objectives, code examples, and outputs demonstrating the use of Python keywords, various operators, and control statements. The document serves as a guide for learning fundamental Python concepts through practical exercises.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

python-practicals (1)

The document outlines three Python programming practicals: Keywords Program, Operator Program, and Control Statement Program. Each practical includes objectives, code examples, and outputs demonstrating the use of Python keywords, various operators, and control statements. The document serves as a guide for learning fundamental Python concepts through practical exercises.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Python Programming Practicals

Practical 1: Keywords Program


Practical Name: Keywords Program Objective: To demonstrate the use of
Python keywords and identify reserved words in Python.
import keyword

def show_python_keywords():
# Get all Python keywords
all_keywords = keyword.kwlist

print("List of Python Keywords:")


for i, kw in enumerate(all_keywords, 1):
print(f"{i}. {kw}")

# Demonstrate use of some keywords


if True:
print("\nExample usage of keywords:")
for num in range(3):
if num == 1:
continue
print(f"Number: {num}")

show_python_keywords()
Output:
List of Python Keywords:
1. False
2. None
3. True
4. and
...
Example usage of keywords:
Number: 0
Number: 2

Practical 2: Operator Program


Practical Name: Operator Program Objective: To demonstrate various oper-
ators in Python including arithmetic, comparison, logical, and bitwise operators.
def demonstrate_operators():
# Arithmetic Operators
a, b = 10, 3
print("Arithmetic Operators:")

1
print(f"Addition: {a + b}")
print(f"Subtraction: {a - b}")
print(f"Multiplication: {a * b}")
print(f"Division: {a / b}")
print(f"Floor Division: {a // b}")
print(f"Modulus: {a % b}")
print(f"Exponentiation: {a ** b}")

# Comparison Operators
print("\nComparison Operators:")
print(f"Equal to: {a == b}")
print(f"Not equal to: {a != b}")
print(f"Greater than: {a > b}")

# Logical Operators
print("\nLogical Operators:")
print(f"AND: {True and False}")
print(f"OR: {True or False}")
print(f"NOT: {not True}")

demonstrate_operators()
Output:
Arithmetic Operators:
Addition: 13
Subtraction: 7
Multiplication: 30
Division: 3.3333333333333335
Floor Division: 3
Modulus: 1
Exponentiation: 1000

Comparison Operators:
Equal to: False
Not equal to: True
Greater than: True

Logical Operators:
AND: False
OR: True
NOT: False

Practical 3: Control Statement Program


Practical Name: Control Statement Program Objective: To demonstrate
the usage of different control statements including if-else, loops, and conditional

2
statements.
def demonstrate_control_statements():
# if-elif-else statement
score = 85
print("Grade Calculation:")
if score >= 90:
grade = 'A'
elif score >= 80:
grade = 'B'
elif score >= 70:
grade = 'C'
else:
grade = 'D'
print(f"Score: {score}, Grade: {grade}")

# for loop with range


print("\nCounting with for loop:")
for i in range(1, 4):
print(f"Count: {i}")

# while loop with break


print("\nWhile loop demonstration:")
counter = 0
while True:
counter += 1
if counter > 3:
break
print(f"While count: {counter}")

demonstrate_control_statements()
Output:
Grade Calculation:
Score: 85, Grade: B

Counting with for loop:


Count: 1
Count: 2
Count: 3

While loop demonstration:


While count: 1
While count: 2
While count: 3
[Note: I can continue with the rest of the practicals. Would you like me to pro-

3
ceed with more? Each practical will follow the same format with clear objectives,
code examples, and outputs.]

You might also like