click here to join WhatsApp link
PYTHON PRACTICAL FILE
Student Name: ____________________
Class/Roll No.: ____________________
Session: ____________________
click here to join WhatsApp link
INDEX
[Link]. Program Page No.
1 Hello World ____
2 Addition of Two ____
Numbers
3 Even or Odd ____
4 Largest of Three ____
Numbers
5 Factorial ____
6 Fibonacci Series ____
7 Prime Number Check ____
8 Palindrome Check ____
9 Reverse a String ____
10 List Operations ____
11 Tuple Example ____
12 Dictionary Example ____
13 File Handling ____
14 Exception Handling ____
15 Class and Object ____
Teacher Signature: ____________________
Student Signature: ____________________
click here to join WhatsApp link
Program 1: Hello World
Objective: To display Hello World.
Code:
print('Hello World')
Output:
Hello World
click here to join WhatsApp link
Program 2: Addition of Two Numbers
Objective: To add two numbers.
Code:
a=10
b=20
print(a+b)
Output:
30
click here to join WhatsApp link
Program 3: Even or Odd
Objective: To check even or odd.
Code:
n=7
print('Even' if n%2==0 else 'Odd')
Output:
Odd
click here to join WhatsApp link
Program 4: Largest of Three Numbers
Objective: To find largest number.
Code:
a,b,c=10,25,15
print(max(a,b,c))
Output:
25
click here to join WhatsApp link
Program 5: Factorial
Objective: To find factorial.
Code:
n=5
f=1
for i in range(1,n+1):
f*=i
print(f)
Output:
120
click here to join WhatsApp link
Program 6: Fibonacci Series
Objective: To print Fibonacci series.
Code:
a,b=0,1
for i in range(5):
print(a,end=' ')
a,b=b,a+b
Output:
0 1 1 2 3
click here to join WhatsApp link
Program 7: Prime Number Check
Objective: To check prime number.
Code:
n=11
for i in range(2,n):
if n%i==0:
print('Not Prime')
break
else:
print('Prime')
Output:
Prime
click here to join WhatsApp link
Program 8: Palindrome Check
Objective: To check palindrome.
Code:
s='madam'
print('Palindrome' if s==s[::-1] else 'Not')
Output:
Palindrome
click here to join WhatsApp link
Program 9: Reverse a String
Objective: To reverse a string.
Code:
s='Python'
print(s[::-1])
Output:
nohtyP
click here to join WhatsApp link
Program 10: List Operations
Objective: To demonstrate list operations.
Code:
l=[1,2,3]
[Link](4)
print(l)
Output:
[1, 2, 3, 4]
click here to join WhatsApp link
Program 11: Tuple Example
Objective: To demonstrate tuple.
Code:
t=(1,2,3)
print(t[1])
Output:
2
click here to join WhatsApp link
Program 12: Dictionary Example
Objective: To demonstrate dictionary.
Code:
d={'A':1,'B':2}
print(d['A'])
Output:
1
click here to join WhatsApp link
Program 13: File Handling
Objective: To write into a file.
Code:
f=open('[Link]','w')
[Link]('Hello')
[Link]()
print('Written')
Output:
Written
click here to join WhatsApp link
Program 14: Exception Handling
Objective: To handle exceptions.
Code:
try:
print(10/0)
except ZeroDivisionError:
print('Error')
Output:
Error
click here to join WhatsApp link
Program 15: Class and Object
Objective: To create a class and object.
Code:
class Student:
def show(self):
print('Student')
s=Student()
[Link]()
Output:
Student