0% found this document useful (0 votes)
9 views7 pages

Python Lab Part2

The document contains a series of Python programs that perform various tasks such as calculating EMI for loans, computing GST, finding the largest and smallest numbers in a list, identifying the third largest and smallest numbers, summing squares of the first 100 natural numbers, printing multiples of a number, and counting vowels in a string. Each program includes user input prompts, calculations, and output statements. The programs are structured to be clear and concise, demonstrating fundamental programming concepts.

Uploaded by

loligottagonow
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views7 pages

Python Lab Part2

The document contains a series of Python programs that perform various tasks such as calculating EMI for loans, computing GST, finding the largest and smallest numbers in a list, identifying the third largest and smallest numbers, summing squares of the first 100 natural numbers, printing multiples of a number, and counting vowels in a string. Each program includes user input prompts, calculations, and output statements. The programs are structured to be clear and concise, demonstrating fundamental programming concepts.

Uploaded by

loligottagonow
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Instruction (Don't write this in record)

Begin each program on a new page

6. Write a program to calculate EMI for Amount, Period and Interest.

PROGRAM
P = float(input("Enter loan amount: "))
annual_rate = float(input("Enter annual interest rate (%): "))
years = int(input("Enter loan tenure (in years): "))

# Convert to monthly values


R = annual_rate / (12 * 100)
N = years * 12

# EMI formula
EMI = (P * R * (1 + R) ** N) / ((1 + R) ** N - 1)

print("Monthly EMI is:", round(EMI, 2))

OUTPUT:
7. Write a program to calculate tax - GST
PROGRAM
price = float(input("Enter original price: "))
gst_rate = float(input("Enter GST rate (%): "))

# GST calculation
gst_price = (price * gst_rate) / 100
total_price = price + gst_price

print("GST:", gst_price)
print("Total Price (Including GST):", total_price)

OUTPUT
8. Write a program to find the largest and smallest numbers in a list.
PROGRAM:
l = []
n = int(input("Enter number of elements: "))
for i in range(n):
num = int(input("Enter number: "))
[Link](num)

largest = l[0]
smallest = l[0]

for num in l:
if num > largest:
largest = num
if num < smallest:
smallest = num

print("Largest number:", largest)


print("Smallest number:", smallest)

OUTPUT
[Link] a python program to find the third largest/smallest number in a
list.
PROGRAM:
n = int(input("Enter number of elements: "))
nums = []
for i in range(n):
value=int(input("Enter number: "))
[Link](value)
# Check if at least 3 elements exist
if n < 3:
print("Not enough elements")
else:
# Third smallest
[Link]()
print("Third smallest:", nums[2])
# Third largest
[Link](reverse=True)
print("Third largest:", nums[2])

OUTPUT:
10. Write a program to find the sum of squares of the first 100 natural
numbers.
PROGRAM:
sum= 0
for i in range(1, 101):
sum+= i * i
print("Sum of squares of first 100 natural numbers:", sum)

OUTPUT:
[Link] a program to print the first ‘n’ multiples of a given number.
PROGRAM:
num = int(input("Enter the number: "))
n = int(input("Enter how many multiples: "))

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


print(num * i, end=' ')

OUTPUT:
12. Write a program to count the number of vowels in a user entered string.
PROGRAM
string = input("Enter a string: ")
count = 0

for ch in string:
if ch in "aeiouAEIOU":
count += 1

print("Number of vowels:", count)

OUTPUT

You might also like