0% found this document useful (0 votes)
10 views4 pages

Python Lab Manual

Uploaded by

anbi112001
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)
10 views4 pages

Python Lab Manual

Uploaded by

anbi112001
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
You are on page 1/ 4

Python Lab Manual

Experiment 1: Simple Interest


Aim: Simple Interest

Code:

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)

Experiment 2: Compound Interest


Aim: Compound Interest

Code:

P = float(input("Enter principal amount: "))


R = float(input("Enter rate of interest: "))
T = float(input("Enter time in years: "))

CI = P * ((1 + R/100)**T) - P
print("Compound Interest = ", CI)

Experiment 3: Leap Year Check


Aim: Leap Year Check

Code:

year = int(input("Enter a year: "))

if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):


print(year, "is a Leap Year")
else:
print(year, "is not a Leap Year")
Experiment 4: Fibonacci Number Check
Aim: Fibonacci Number Check

Code:

import math

def is_fibonacci(n):
return (math.isqrt(5*n*n + 4)**2 == 5*n*n + 4) or (math.isqrt(5*n*n - 4)**2 == 5*n*n - 4)

num = int(input("Enter a number: "))


if is_fibonacci(num):
print(num, "is a Fibonacci number")
else:
print(num, "is not a Fibonacci number")

Experiment 5: Matrix Multiplication


Aim: Matrix Multiplication

Code:

A = [[1, 2], [3, 4]]


B = [[5, 6], [7, 8]]
result = [[0, 0], [0, 0]]

for i in range(len(A)):
for j in range(len(B[0])):
for k in range(len(B)):
result[i][j] += A[i][k] * B[k][j]

print("Resultant Matrix:")
for r in result:
print(r)

Experiment 6: Average of Numbers


Aim: Average of Numbers

Code:

n = int(input("How many numbers? "))


total = 0
for i in range(n):
num = float(input("Enter number: "))
total += num

average = total / n
print("Average =", average)

Experiment 7: Palindrome Number Check


Aim: Palindrome Number Check

Code:

num = int(input("Enter a number: "))


reverse = int(str(num)[::-1])

if num == reverse:
print(num, "is a Palindrome number")
else:
print(num, "is not a Palindrome number")

Experiment 8: Prime Number Check


Aim: Prime Number Check

Code:

num = int(input("Enter a number: "))

if num > 1:
for i in range(2, int(num**0.5)+1):
if num % i == 0:
print(num, "is not a prime number")
break
else:
print(num, "is a prime number")
else:
print(num, "is not a prime number")

Experiment 9: Random Number Generator


Aim: Random Number Generator
Code:

import random
print("Random Number:", random.randint(1, 100))

Experiment 10: Swap Two Variables


Aim: Swap Two Variables

Code:

a = int(input("Enter first number (a): "))


b = int(input("Enter second number (b): "))

a, b = b, a
print("After swapping: a =", a, ", b =", b)

You might also like