0% found this document useful (0 votes)
7 views10 pages

10 AI Practical Programs For PT-2

The document contains ten programming exercises, each with a description, code, and example output. The programs cover various topics such as calculating simple interest, checking character types, finding maximum numbers, calculating electricity bills, summing natural numbers, printing multiplication tables, and working with lists of numbers. Each program is designed to demonstrate fundamental programming concepts and user input handling.

Uploaded by

vedantambani322
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)
7 views10 pages

10 AI Practical Programs For PT-2

The document contains ten programming exercises, each with a description, code, and example output. The programs cover various topics such as calculating simple interest, checking character types, finding maximum numbers, calculating electricity bills, summing natural numbers, printing multiplication tables, and working with lists of numbers. Each program is designed to demonstrate fundamental programming concepts and user input handling.

Uploaded by

vedantambani322
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
You are on page 1/ 10

PROGRAM-1

Write a program to compute the simple interest. Accept the values of principal, rate and time
from the user.

CODE:
principal = float(input("Enter the principal amount: "))
rate = float(input("Enter the rate of interest: "))
time = float(input("Enter the time period in years: "))
simple_interest = (principal * rate * time) / 100
print("The simple interest is:", simple_interest)

OUTPUT
Enter the principal amount: 50000
Enter the rate of interest: 15
Enter the time period in years: 5
The simple interest is: 37500.0

Page 1 of 10
PROGRAM-2
Write a program to check whether the given character is an uppercase letter or lowercase letter or
a digit or a special character.

CODE:
char = input("Enter a character: ")
if char.isupper():
print("The character is an uppercase letter.")
elif char.islower():
print("The character is a lowercase letter.")
elif char.isdigit():
print("The character is a digit.")
else:
print("The character is a special character.")

OUTPUT

Enter a character: D
The character is an uppercase letter.

Page 2 of 10
PROGRAM-3
Write a program to find the maximum number out of the given three numbers.

CODE:
num1 = int(input("Enter the first number: "))

num2 = int(input("Enter the second number: "))

num3 = int(input("Enter the third number: "))

if num1 >= num2 and num1 >= num3:

largest = num1

elif num2 >= num1 and num2 >= num3:

largest = num2

else:

largest = num3

print("The largest number is:", largest)

OUTPUT
Enter the first number: 45

Enter the second number: 56

Enter the third number: 35

The largest number is: 56

Page 3 of 10
PROGRAM-4
An electric power distribution company charges its domestic consumers as follows:

Write a program that read the customer number & power consumed and prints the amount to
be paid by the customer. Note that output should be well formatted.

CODE:
custno = int(input("Enter customer number: "))
units = int(input("Enter power consumed (units): "))
# Initialize the amount to be paid
amount = 0

# Calculate the amount based on consumption units


if units <= 100:
amount = units * 1
elif units <= 300:
amount = 100 + (units - 100) * 1.25
elif units <= 500:
amount = 350 + (units - 300) * 1.50
else:
amount = 650 + (units - 500) * 1.75

Page 4 of 10
# Print the output in a well-formatted manner
print("\n----- Electricity Bill -----")
print(f"Customer Number : ", custno)
print("Units Consumed : “, units")
print("Amount to be Paid: Rs.",amount)
print("------------------------------")

OUTPUT
Enter customer number: 101
Enter power consumed (units): 600

----- Electricity Bill -----


Customer Number : 101
Units Consumed : 600
Amount to be Paid: Rs. 825.0
------------------------------

Page 5 of 10
PROGRAM-5
Write a program to display summation of first N natural numbers.
For example if N =10 then output will be Sum 55

CODE:
N = int(input("Enter a positive integer N: "))
Sum = 0
for i in range(1, N + 1):
Sum += i
print("The sum of the first", N, "natural numbers is:", Sum)

OUTPUT
Enter a positive integer N: 20
The sum of the first 20 natural numbers is: 210

PROGRAM-6
Write a program to print a multiplication table of any positive integer N.
For example if N = 5 then output will be 5 10 15 20 25 30 35 40 45 50

CODE:
N = int(input("Enter a positive integer N: "))
for i in range(1, 11):
print(N * i, end=' ')

OUTPUT
Enter a positive integer N: 15
15 30 45 60 75 90 105 120 135 150

Page 6 of 10
PROGRAM-7
Write a program to create a list of students’ marks with user-defined values and find the total
and maximum of the marks.
For example L = [85, 45, 90, 55, 65, 60] then output will be:
Total marks 400
Highest marks 90

CODE:
marks =eval(input('enter list of marks '))
# Calculate the total marks
total = sum(marks)
# Find the highest mark
maxmarks =max(marks)
#display
print("total marks ",total)
print("highest marks ",maxmarks)

OUTPUT
enter list of marks [85,45,90,55,65,60]
total marks 400
highest marks 90

Page 7 of 10
PROGRAM-8
Write a program to create a list of numbers and find the sum of the even elements and the sum
of the odd elements present in it.
For example L = [ 5, 3, 4, 2, 7, 6] then output will be :
Even Sum 12
Odd Sum 15

CODE:
marks =eval(input('enter list of marks '))
# Calculate the total marks
total = sum(marks)
# Find the highest mark
maxmarks =max(marks)
#display
print("total marks ",total)
print("highest marks ",maxmarks)

OUTPUT
enter list of marks [85,45,90,55,65,60]
total marks 400
highest marks 90

Page 8 of 10
PROGRAM-9
Write a program to create a list of numbers and find the sum of the even location elements
and the sum of the odd location elements present in it.
For example L = [ 5, 3, 4, 2, 7, 6] then output will be :
Even Sum 16
Odd Sum 11

CODE:
nlist =eval(input('enter list of numbers '))
evenpos, oddpos =0, 0
for i in range(len(nlist)):
if i% 2 ==0:
evenpos += nlist[i]
else:
oddpos += nlist[i]
print("even sum ",evenpos)
print("odd sum ",oddpos)

OUTPUT
enter list of numbers [ 5, 3, 4, 2, 7, 6]
even sum 16
odd sum 11

Page 9 of 10
PROGRAM-10
Write a program to find the factorial value of N. Accept the value of N from the user.
For example factorial of 5 is 5 x 4 x 3 x 2 x 1 which is 120

CODE:
N = int(input("Enter the value of N: "))
fact = 1
for i in range(1, N + 1):
fact *= i
print("Factorial ",fact)

OUTPUT
Enter the value of N: 6
Factorial 720

Page 10 of 10

You might also like