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

Python Practical Assignment

The document is a practical assignment for Python programming, detailing 25 programs to be completed by students. Each program includes an aim, code, and example output. Topics covered range from calculating simple interest to printing various patterns and checking for prime numbers.

Uploaded by

dilipkashyap.h1
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 views27 pages

Python Practical Assignment

The document is a practical assignment for Python programming, detailing 25 programs to be completed by students. Each program includes an aim, code, and example output. Topics covered range from calculating simple interest to printing various patterns and checking for prime numbers.

Uploaded by

dilipkashyap.h1
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

PYTHON PROGRAMMING

PRACTICAL ASSIGNMENT

Name
Roll No
Class / Division
Subject Python Programming
Academic Year 2024 - 2025

Total Programs: 25 | Pages: Practical Copy


Index

Sr. No. Program Title Date Sign


1 calculate Simple Interest

2 calculate Area & Circumference of Circle

3 find Greater of Two Numbers

4 find Greater of Three Numbers

5 check if a Number is Even or Odd

6 check if Number is Negative, Positive or Zero

7 calculate Volume of Cone

8 find Grade of Obtained Marks

9 check if a Number is Prime or Not

10 find all Prime Numbers between 1 to 100

11 find Factorial of a Given Number

12 print Fibonacci Series up to N Terms

13 find Reverse of a Given Number

14 check if a Number is Palindrome or Not

15 find Sum of First N Natural Numbers

16 Print Number Pattern

17 Print Star Pattern

18 Print Star Pyramid Pattern

19 Print Number Pyramid Pattern

20 Print Inverted Star Pattern

21 Print Alphabet Pattern

22 Print Alphabet Pattern (Variant)

23 Print Number Palindrome Pattern

24 Print Alphabet Reverse Pattern

25 Print Number Diamond Pattern


Q1. WAP to calculate Simple Interest
Aim:
To write a Python program to calculate Simple Interest.

Program Code:

# Simple Interest Calculator


p = float(input('Enter Principal Amount: '))
r = float(input('Enter Rate of Interest: '))
t = float(input('Enter Time (in years): '))

si = (p * r * t) / 100
print('Simple Interest =', si)

Output:

Enter Principal Amount: 1000


Enter Rate of Interest: 5
Enter Time (in years): 2
Simple Interest = 100.0
Q2. WAP to calculate Area & Circumference of Circle
Aim:
To write a Python program to calculate area and circumference of a circle.

Program Code:

# Area and Circumference of Circle


import math

r = float(input('Enter Radius of Circle: '))

area = [Link] * r * r
circumference = 2 * [Link] * r

print('Area =', round(area, 2))


print('Circumference =', round(circumference, 2))

Output:

Enter Radius of Circle: 7


Area = 153.94
Circumference = 43.98
Q3. WAP to find Greater of Two Numbers
Aim:
To write a Python program to find the greater of two numbers.

Program Code:

# Greater of Two Numbers


a = int(input('Enter first number: '))
b = int(input('Enter second number: '))

if a > b:
print(a, 'is greater')
elif b > a:
print(b, 'is greater')
else:
print('Both numbers are equal')

Output:

Enter first number: 45


Enter second number: 32
45 is greater
Q4. WAP to find Greater of Three Numbers
Aim:
To write a Python program to find the greatest among three numbers.

Program Code:

# Greater of Three Numbers


a = int(input('Enter first number: '))
b = int(input('Enter second number: '))
c = int(input('Enter third number: '))

if a >= b and a >= c:


print(a, 'is greatest')
elif b >= a and b >= c:
print(b, 'is greatest')
else:
print(c, 'is greatest')

Output:

Enter first number: 15


Enter second number: 42
Enter third number: 31
42 is greatest
Q5. WAP to check if a Number is Even or Odd
Aim:
To write a Python program to check whether a given number is even or odd.

Program Code:

# Even or Odd
n = int(input('Enter a number: '))

if n % 2 == 0:
print(n, 'is Even')
else:
print(n, 'is Odd')

Output:

Enter a number: 17
17 is Odd
Q6. WAP to check if Number is Negative, Positive or Zero
Aim:
To write a Python program to check whether a number is negative, positive, or zero.

Program Code:

# Positive, Negative or Zero


n = float(input('Enter a number: '))

if n > 0:
print('Number is Positive')
elif n < 0:
print('Number is Negative')
else:
print('Number is Zero')

Output:

Enter a number: -5
Number is Negative
Q7. WAP to calculate Volume of Cone
Aim:
To write a Python program to calculate the volume of a cone.

Program Code:

# Volume of Cone
import math

r = float(input('Enter radius of cone: '))


h = float(input('Enter height of cone: '))

volume = (1/3) * [Link] * r * r * h


print('Volume of Cone =', round(volume, 2))

Output:

Enter radius of cone: 5


Enter height of cone: 10
Volume of Cone = 261.8
Q8. WAP to find Grade of Obtained Marks
Aim:
To write a Python program to determine the grade based on marks obtained.

Program Code:

# Grade Finder
marks = int(input('Enter marks (out of 100): '))

if marks >= 90:


print('Grade: A+')
elif marks >= 80:
print('Grade: A')
elif marks >= 70:
print('Grade: B')
elif marks >= 60:
print('Grade: C')
elif marks >= 50:
print('Grade: D')
elif marks >= 35:
print('Grade: E (Pass)')
else:
print('Grade: F (Fail)')

Output:

Enter marks (out of 100): 82


Grade: A
Q9. WAP to check if a Number is Prime or Not
Aim:
To write a Python program to check whether a given number is prime or not.

Program Code:

# Prime Number Check


n = int(input('Enter a number: '))
is_prime = True

if n < 2:
is_prime = False
else:
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
is_prime = False
break

if is_prime:
print(n, 'is a Prime number')
else:
print(n, 'is NOT a Prime number')

Output:

Enter a number: 29
29 is a Prime number
Q10. WAP to find all Prime Numbers between 1 to 100
Aim:
To write a Python program to print all prime numbers between 1 and 100.

Program Code:

# All Prime Numbers from 1 to 100


print('Prime numbers between 1 to 100:')

for n in range(2, 101):


is_prime = True
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
is_prime = False
break
if is_prime:
print(n, end=' ')

Output:

Prime numbers between 1 to 100:


2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97
Q11. WAP to find Factorial of a Given Number
Aim:
To write a Python program to find the factorial of a given number.

Program Code:

# Factorial
n = int(input('Enter a number: '))
factorial = 1

if n < 0:
print('Factorial not defined for negative numbers')
else:
for i in range(1, n + 1):
factorial *= i
print('Factorial of', n, '=', factorial)

Output:

Enter a number: 6
Factorial of 6 = 720
Q12. WAP to print Fibonacci Series up to N Terms
Aim:
To write a Python program to print Fibonacci series up to n terms.

Program Code:

# Fibonacci Series
n = int(input('Enter number of terms: '))
a, b = 0, 1

print('Fibonacci Series:')
for i in range(n):
print(a, end=' ')
a, b = b, a + b

Output:

Enter number of terms: 8


Fibonacci Series:
0 1 1 2 3 5 8 13
Q13. WAP to find Reverse of a Given Number
Aim:
To write a Python program to find the reverse of a given number.

Program Code:

# Reverse of a Number
n = int(input('Enter a number: '))
rev = 0
temp = n

while temp != 0:
digit = temp % 10
rev = rev * 10 + digit
temp //= 10

print('Reverse of', n, '=', rev)

Output:

Enter a number: 12345


Reverse of 12345 = 54321
Q14. WAP to check if a Number is Palindrome or Not
Aim:
To write a Python program to check whether a given number is a palindrome.

Program Code:

# Palindrome Check
n = int(input('Enter a number: '))
rev = 0
temp = n

while temp != 0:
digit = temp % 10
rev = rev * 10 + digit
temp //= 10

if n == rev:
print(n, 'is a Palindrome')
else:
print(n, 'is NOT a Palindrome')

Output:

Enter a number: 121


121 is a Palindrome
Q15. WAP to find Sum of First N Natural Numbers
Aim:
To write a Python program to find the sum of first N natural numbers.

Program Code:

# Sum of First N Natural Numbers


n = int(input('Enter value of N: '))
total = 0

for i in range(1, n + 1):


total += i

print('Sum of first', n, 'natural numbers =', total)

# Using formula
formula_sum = n * (n + 1) // 2
print('Using formula: N*(N+1)/2 =', formula_sum)

Output:

Enter value of N: 10
Sum of first 10 natural numbers = 55
Using formula: N*(N+1)/2 = 55
Q16. Print Number Pattern
Aim:
To write a Python program to print number pattern (1, 1 2, 1 2 3 ...).

Program Code:

# Number Pattern
n = int(input('Enter number of rows: '))

for i in range(1, n + 1):


for j in range(1, i + 1):
print(j, end=' ')
print()

Output:

Enter number of rows: 4


1
1 2
1 2 3
1 2 3 4
Q17. Print Star Pattern
Aim:
To write a Python program to print a star (*) pattern.

Program Code:

# Star Pattern
n = int(input('Enter number of rows: '))

for i in range(1, n + 1):


for j in range(i):
print('*', end=' ')
print()

Output:

Enter number of rows: 4


*
* *
* * *
* * * *
Q18. Print Star Pyramid Pattern
Aim:
To write a Python program to print a star pyramid pattern.

Program Code:

# Star Pyramid Pattern


n = int(input('Enter number of rows: '))

for i in range(1, n + 1):


print(' ' * (n - i), end='')
print('* ' * i)

Output:

Enter number of rows: 4


*
* *
* * *
* * * *
Q19. Print Number Pyramid Pattern
Aim:
To write a Python program to print a number pyramid where numbers appear sequentially.

Program Code:

# Number Pyramid Pattern


n = int(input('Enter number of rows: '))
num = 1

for i in range(1, n + 1):


for j in range(i):
print(num, end=' ')
num += 1
print()

Output:

Enter number of rows: 4


1
2 3
4 5 6
7 8 9 10
Q20. Print Inverted Star Pattern
Aim:
To write a Python program to print an inverted star pattern.

Program Code:

# Inverted Star Pattern


n = int(input('Enter number of rows: '))

for i in range(n, 0, -1):


for j in range(i):
print('*', end=' ')
print()

Output:

Enter number of rows: 4


* * * *
* * *
* *
*
Q21. Print Alphabet Pattern
Aim:
To write a Python program to print an alphabet pattern (A, AB, ABC ...).

Program Code:

# Alphabet Pattern
n = int(input('Enter number of rows: '))

for i in range(1, n + 1):


for j in range(i):
print(chr(65 + j), end=' ')
print()

Output:

Enter number of rows: 4


A
A B
A B C
A B C D
Q22. Print Alphabet Pattern (Variant)
Aim:
To write a Python program to print another variant of the alphabet pattern.

Program Code:

# Alphabet Pattern Variant


n = int(input('Enter number of rows: '))

for i in range(n, 0, -1):


for j in range(i):
print(chr(65 + j), end=' ')
print()

Output:

Enter number of rows: 4


A B C D
A B C
A B
A
Q23. Print Number Palindrome Pattern
Aim:
To write a Python program to print number palindrome pattern.

Program Code:

# Number Palindrome Pattern


n = int(input('Enter number of rows: '))

for i in range(1, n + 1):


for j in range(1, i + 1):
print(j, end=' ')
for j in range(i - 1, 0, -1):
print(j, end=' ')
print()

Output:

Enter number of rows: 4


1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
Q24. Print Alphabet Reverse Pattern
Aim:
To write a Python program to print the alphabet reverse pattern.

Program Code:

# Alphabet Reverse Pattern


n = int(input('Enter number of rows: '))

for i in range(n, 0, -1):


for j in range(i):
print(chr(65 + j), end=' ')
print(' ', end='')
for j in range(i - 1, -1, -1):
print(chr(65 + j), end=' ')
print()

Output:

Enter number of rows: 4


A B C D D C B A
A B C C B A
A B B A
A
Q25. Print Number Diamond Pattern
Aim:
To write a Python program to print a number diamond pattern.

Program Code:

# Number Diamond Pattern


n = int(input('Enter number of rows: '))

for i in range(n, 0, -1):


print(' ' * (n - i), end='')
for j in range(1, i + 1):
print(j, end=' ')
for j in range(i - 1, 0, -1):
print(j, end=' ')
print()

Output:

Enter number of rows: 4


1 2 3 4 3 2 1
1 2 3 2 1
1 2 1
1

You might also like