Thanks to visit codestin.com
Credit goes to www.scribd.com

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

Class10 AI Practicals

Uploaded by

tanchumma
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 views2 pages

Class10 AI Practicals

Uploaded by

tanchumma
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/ 2

Class 10 AI Practical Programs (Sets A-D)

SET A

Q: Write a program to input a number and check whether it is prime or not


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

if num > 1:
for i in range(2, num):
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.")

Q: Write a program to input a list and print only odd elements from it
lst = list(map(int, input("Enter numbers separated by space: ").split()))

print("Odd elements in the list are:")


for i in lst:
if i % 2 != 0:
print(i, end=" ")

SET B

Q: Write a program to input a list, calculate and print sum of all its elements
lst = list(map(int, input("Enter numbers separated by space: ").split()))
total = sum(lst)
print("Sum of all elements =", total)

Q: Write a program to input a number from the user and print its table till 10
num = int(input("Enter a number: "))
print("Multiplication Table of", num)
for i in range(1, 11):
print(num, "x", i, "=", num * i)

SET C

Q: Write a program to input a list, calculate and print sum of only even elements
lst = list(map(int, input("Enter numbers separated by space: ").split()))
even_sum = sum(i for i in lst if i % 2 == 0)
print("Sum of even elements =", even_sum)

Q: Write a program to input a number and calculate its factorial


num = int(input("Enter a number: "))
fact = 1
for i in range(1, num + 1):
fact *= i
print("Factorial of", num, "=", fact)

SET D

Q: Write a program to input a list, calculate and print sum of only single digit elements
lst = list(map(int, input("Enter numbers separated by space: ").split()))
single_digit_sum = sum(i for i in lst if 0 <= i <= 9)
print("Sum of single-digit elements =", single_digit_sum)

Q: Write a program to input a number (n) and print all natural numbers from 1 till n using loop
n = int(input("Enter a number: "))
print("Natural numbers from 1 to", n)
for i in range(1, n + 1):
print(i, end=" ")

You might also like