[go: up one dir, main page]

0% found this document useful (0 votes)
36 views24 pages

Project File (AI) - Watermark

Uploaded by

kumarnaitik008
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)
36 views24 pages

Project File (AI) - Watermark

Uploaded by

kumarnaitik008
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/ 24

Kanha Makhan Public School

ARTIFICIAL INTELLIGENCE (417)


REPORT FILE

PREPARED BY: SUBMITTED TO:


MANVENDRA SINGH LODHI RUDRA SIR

Roll No.:

X (Session: 2024-25)
- CERTIFICATE -

This is to certify that this Report file is the Bonafide work of

Miss / Master MANVENDRA SINGH LODHI of

Class 10th, Roll No. in the session 2024-25

of Kanha Makhan Public School, Mathura carried out in the

school under my supervision.

Teacher’s Signature
Acknowledgement
I am thankful to my Artificial Intelligence teacher for
guidance and support. I also thank my Principal Mr.
Pramod Sharma. I would also like to thank my parents and
my classmates for encouraging me during the course of this
report file.
Finally, I would like to thank CBSE for giving me this
opportunity to undertake this practical work.
Python
Program
Kanha Makhan Public School
Subject - Artificial Intelligence (417)
Practical Questions

1. Write a program to accept numbers till the user entered zero and then find
their average.
2. Write a program to check whether a number is palindrome or not.
3. Write a program to obtain principal amount, rate of interest and time from
the user and compute simple interest.
4. Write a program to display the sum of even numbers up to number n entered
by the user.
5. Write a program to swap two numbers without using the third variable.
6. Write a program to print the table of any number by using while loop.
7. Write a program to print whether a given character is an uppercase or
lowercase character or digit or any other character.
8. Write a program to display all numbers within a range except the prime
numbers.
9. Write a program to count the number of vowels in a string using for loop.
10.Write a program to calculate the sum of numbers from 1 to 100 using a while
loop
11.Write a program to calculate the area of circle, rectangle and triangle
depending upon user choice. The choice should be entered by the user in the
form of a menu. Wrong choice should be addressed.
12.Write a program to input two numbers and swap both the numbers by using
third number.
13.Write a program to print the following pattern
4321
432
43
4
14.Write a program to print the following pattern.
*
**
***
****
*****
15.Write a program to take the input of a number ‘n’ and then find and display
its factorial (n!).
(For Ex. 5! =5*4*3*2*1 i.e.120.)
Problem 1:

Code:

total = 0
count = 0

while True:
num = float(input("Enter a number (0 to stop): "))
if num == 0:
break
total += num
count += 1

if count > 0:
average = total / count
print("The average is: ", average)
else:
print("No numbers were entered.")

Output:

Enter a number (0 to stop): 99


Enter a number (0 to stop): 8
Enter a number (0 to stop): 0
The average is: 53.5
Problem 2:

Code:

# Input from the user


number = input("Enter a number: ")

# Check if the number is a palindrome


if number == number[::-1]:
print(number, "is a palindrome.")
else:
print(number, "is not a palindrome.")

Output:

Case 1:
Enter a number: 122
122 is not a palindrome.

Case 2:
Enter a number: 121
121 is a palindrome.
Problem 3:

Code:

# Input values from the user


P = float(input("Enter the principal amount: "))
R = float(input("Enter the rate of interest (in %): "))
T = float(input("Enter the time (in years): "))

# Calculate simple interest


SI = (P * R * T) / 100

# Output the result


print("The simple interest is:", SI)

Output:

Enter the principal amount: 1000


Enter the rate of interest (in %): 5
Enter the time (in years): 3
The simple interest is: 150.0
Problem 4:

Code:

# Input from the user


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

# Initialize sum
sum_of_evens = 0

# Calculate the sum of even numbers


for i in range(2, n + 1, 2):
sum of evens += i

# Output the result


print("The sum of even numbers up to", n, "is:",
sum_of_evens)

Output:

Enter a number: 10
The sum of even numbers up to 10 is: 30
Problem 5:

Code:

# Input two numbers from the user


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

# Swap using tuple unpacking


a, b = b, a

# Output the swapped numbers


print("After swapping:")
print("First number:", a)
print("Second number:", b)

Output:

Enter the first number: 5


Enter the second number: 10
After swapping:
First number: 10
Second number: 5
Problem 6:

Code:

# Input a number from the user


number = int(input("Enter a number: "))
i=1

# Print the multiplication table


while i <= 10:
print(number, "x", i, "=", number * i)
i += 1

Output:

Enter a number: 3
3x1=3
3x2=6
3x3=9
3 x 4 = 12
3 x 5 = 15
3 x 6 = 18
3 x 7 = 21
3 x 8 = 24
3 x 9 = 27
3 x 10 = 30
Problem 7:

Code:

# Input a character from the user


char = input("Enter a character: ")

# Check and print the type of character


if char.isupper():
print("Uppercase letter")
elif char.islower():
print("Lowercase letter")
elif char.isdigit():
print("Digit")
else:
print("Other character")

Output:

Enter a character: A
Uppercase letter

Enter a character: b
Lowercase letter

Enter a character: 5
Digit

Enter a character: @
Other character
Problem 8:

Code:

def is prime(num):
if num < 2:
return False
for i in range(2, int(num**0.5) + 1):
if num % i == 0:
return False
return True

# Input the range from the user


start = int(input("Enter the start of the range: "))
end = int(input("Enter the end of the range: "))

# Display non-prime numbers in the range


for number in range(start, end + 1):
if not is prime(number):
print(number)

Output:

Enter the start of the range: 10


Enter the end of the range: 20
10
12
14
15
16
18
20
Problem 9:

Code:

# Input from the user


input string = input("Enter a string: ")

# Initialize count
count = 0

# Count vowels using a for loop


for char in input string:
if char in "aeiouAEIOU":
count += 1

# Print the result


print("Number of vowels:", count)

Output:

Enter a string: Hello World


Number of vowels: 3
Problem 10:

Code:

# Initialize variables
sum of numbers = 0
number = 1

# Calculate the sum using a while loop


while number <= 100:
sum of numbers += number
number += 1

# Output the result


print(sum of numbers)

Output:

5050
Problem 11:

Code:

print("Choose a shape to calculate the area:")


print("1. Circle")
print("2. Rectangle")
print("3. Triangle")
print("4. Exit")

choice = input("Enter your choice (1-4): ")

if choice == '1':
radius = float(input("Enter the radius of the circle: "))
area = 3.14 * (radius ** 2) # Using 3.14 as an
approximation of π
print(f"The area of the circle is: {area:.2f}")

elif choice == '2':


length = float(input("Enter the length of the rectangle: "))
width = float(input("Enter the width of the rectangle: "))
area = length * width
print(f"The area of the rectangle is: {area:.2f}")

elif choice == '3':


base = float(input("Enter the base of the triangle: "))
height = float(input("Enter the height of the triangle: "))
area = 0.5 * base * height
print(f"The area of the triangle is: {area:.2f}")

elif choice == '4':


print("Exiting the program.")

else:
print("Invalid choice! Please select a valid option (1-4).")

Output:

Case 1:
Choose a shape to calculate the area:
1. Circle
2. Rectangle
3. Triangle
4. Exit
Enter your choice (1-4): 1
Enter the radius of the circle: 5
The area of the circle is: 78.50

Case 2:
Choose a shape to calculate the area:
1. Circle
2. Rectangle
3. Triangle
4. Exit
Enter your choice (1-4): 2
Enter the length of the rectangle: 4
Enter the width of the rectangle: 3
The area of the rectangle is: 12.00
Case 3:
Choose a shape to calculate the area:
1. Circle
2. Rectangle
3. Triangle
4. Exit
Enter your choice (1-4): 3
Enter the base of the triangle: 6
Enter the height of the triangle: 4
The area of the triangle is: 12.00

Case 5:
Choose a shape to calculate the area:
1. Circle
2. Rectangle
3. Triangle
4. Exit
Enter your choice (1-4): 5
Invalid choice! Please select a valid option (1-4).

Case 5:
Choose a shape to calculate the area:
1. Circle
2. Rectangle
3. Triangle
4. Exit
Enter your choice (1-4): 4
Exiting the program.
Problem 12:

Code:

# Input: Get two numbers from the user


num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))

# Swap using a third variable


temp = num1
num1 = num2
num2 = temp

# Output: Display swapped values


print("After swapping: num1 =", num1, ", num2 =", num2)

Output:

Enter the first number: 15


Enter the second number: 30
After swapping: num1 = 30.0 , num2 = 15.0
Problem 13:

Code:

# Number of rows
rows = 4

# Outer loop for each row


for i in range(1, rows + 1):
# Inner loop for printing numbers
for j in range(rows, i - 1, -1):
print(j, end="")
# Move to the next line after each row
print()

Output:

4321
432
43
4
Problem 14:

Code:

# Number of rows for the pattern


rows = 5

# Loop to print the pattern


for i in range(1, rows + 1):
print('*' * i) # Print '*' repeated i times

Output:

*
**
***
****
*****
Problem 15:

Code:

# Take input from the user


n = int(input("Enter a number to find its factorial: "))

# Calculate factorial using a loop


fact = 1
for i in range(1, n + 1):
fact *= i

# Display the result


print(f"The factorial of {n} is {fact}.")

Output:

Enter a number to find its factorial: 6


The factorial of 6 is 720.
Bibliography
• Google
• YouTube
• Blackbox AI
|END|

You might also like