Project File (AI) - Watermark
Project File (AI) - Watermark
Roll No.:
X (Session: 2024-25)
- CERTIFICATE -
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:
Code:
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:
Output:
Code:
# Initialize sum
sum_of_evens = 0
Output:
Enter a number: 10
The sum of even numbers up to 10 is: 30
Problem 5:
Code:
Output:
Code:
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:
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
Output:
Code:
# Initialize count
count = 0
Output:
Code:
# Initialize variables
sum of numbers = 0
number = 1
Output:
5050
Problem 11:
Code:
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}")
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:
Output:
Code:
# Number of rows
rows = 4
Output:
4321
432
43
4
Problem 14:
Code:
Output:
*
**
***
****
*****
Problem 15:
Code:
Output: