GRADE -10 SUBJECT: COMPUTER SCIENCE
From September 8th to September 12th, the Computer Science Practical Exam will be
conducted in their respective computer classes based on the programs given below.
PYTHON PRACTICAL PROGRAMS
1. Program to depict the usage of arithmetic operators.
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
print("Addition:", a + b)
print("Subtraction:", a - b)
print("Multiplication:", a * b)
print("Division:", a / b)
print("Modulus:", a % b)
print("Exponent:", a ** b)
print("Floor Division:", a // b)
Sample Output:
Enter first number: 10
Enter second number: 3
Addition: 13
Subtraction: 7
Multiplication: 30
Division: 3.3333333333333335
Modulus: 1
Exponent: 1000
Floor Division: 3
2. Program to accept 3 numbers and display sum & product.
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
c = int(input("Enter third number: "))
sum_total = a + b + c
product = a * b * c
print("Sum =", sum_total)
print("Product =", product)
Sample Output:
Enter first number: 2
Enter second number: 3
Enter third number: 4
Sum = 9
Product = 24
3. Program to print the following pattern.
rows = 5
for i in range(1, rows + 1):
print("* " * i)
Sample Output:
*
**
***
****
*****
4. Program to accept a number and print first 10 multiples (without for loop)
n = int(input("Enter a number: "))
print("First 10 multiples of", n)
print(n*1, n*2, n*3, n*4, n*5, n*6, n*7, n*8, n*9, n*10)
Sample Output:
Enter a number: 7
First 10 multiples of 7
7 14 21 28 35 42 49 56 63 70
5. Program to print factorial of any number input by the user.
num = int(input("Enter a number to find factorial: "))
factorial = 1
for i in range(1, num + 1):
factorial *= i
print("Factorial of", num, "is", factorial)
Sample Output:
Enter a number to find factorial: 5
Factorial of 5 is 120
6. Program to enter a number and print if it is even or odd.
num = int(input("Enter a number: "))
if num % 2 == 0:
print(num, "is Even")
else:
print(num, "is Odd")
Sample Output:
Enter a number: 7
7 is Odd
7. Program to create Python list with five data items and print their data types.
my_list = [10, "Hello", 3.5, True, [1,2,3]]
for item in my_list:
print(item, "is of type", type(item))
Sample Output:
10 is of type <class 'int'>
Hello is of type <class 'str'>
3.5 is of type <class 'float'>
True is of type <class 'bool'>
[1, 2, 3] is of type <class 'list'>
8. Create a list to accept 3 numbers and an integer from the user, combine in a
single variable, and print.
n1 = int(input("Enter first number: "))
n2 = int(input("Enter second number: "))
n3 = int(input("Enter third number: "))
num = int(input("Enter an integer: "))
combined_list = [n1, n2, n3, num]
print("Combined List:", combined_list)
Sample Output:
Enter first number: 1
Enter second number: 2
Enter third number: 3
Enter an integer: 10
Combined List: [1, 2, 3, 10]
9. Program to enter a number and check whether it's a prime number.
num = int(input("Enter a number: "))
if num > 1:
for i in range(2, int(num**0.5) + 1):
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")
Sample Output:
Enter a number: 13
13 is a prime number
10. Program to print the sum of all numbers till N entered by the user.
N = int(input("Enter a number N: "))
total = 0
for i in range(1, N + 1):
total += i
print("Sum of numbers from 1 to", N, "is", total)
Sample Output:
Enter a number N: 10
Sum of numbers from 1 to 10 is 55
11. Program to find the area of a triangle.
a = float(input("Enter side a: "))
b = float(input("Enter side b: "))
c = float(input("Enter side c: "))
s = (a + b + c) / 2
area = (s * (s - a) * (s - b) * (s - c)) ** 0.5
print("Area of the triangle is", area)
Sample Output:
Enter side a: 3
Enter side b: 4
Enter side c: 5
Area of the triangle is 6.0
12. Program to check whether a number is an Armstrong number.
num = int(input("Enter a number: "))
sum = 0
temp = num
digits = len(str(num))
while temp > 0:
digit = temp % 10
sum += digit ** digits
temp //= 10
if num == sum:
print(num, "is an Armstrong number")
else:
print(num, "is not an Armstrong number")
Sample Output:
Enter a number: 153
153 is an Armstrong number
13. Program to input the age of 20 persons and count the number of people in age
groups
Age Groups:
15 to 20 years
21 to 35 years
Above 35 years
# Initialize counters
count_15_20 = 0
count_21_35 = 0
count_above_35 = 0
# Input ages of 20 persons
for i in range(1, 21):
age = int(input(“Enter age of person”))
if 15 <= age <= 20:
count_15_20 += 1
elif 21 <= age <= 35:
count_21_35 += 1
elif age > 35:
count_above_35 += 1
# Display results
print("Number of people aged 15-20:", count_15_20)
print("Number of people aged 21-35:", count_21_35)
print("Number of people above 35:", count_above_35)
Sample Output:
Enter age of person 1: 18
Enter age of person 2: 22
Enter age of person 3: 36
Enter age of person 4: 19
Enter age of person 5: 25
Number of people aged 15-20: 2
Number of people aged 21-35: 2
Number of people above 35: 1
14. Program to print first N Fibonacci numbers.
N = int(input("Enter how many Fibonacci numbers to print: "))
a, b = 0, 1
print("Fibonacci Series:", end=" ")
for _ in range(N):
print(a, end=" ")
a, b = b, a + b
Sample Output:
Enter how many Fibonacci numbers to print: 10
Fibonacci Series: 0 1 1 2 3 5 8 13 21 34
15. Python program to find the mean of a list using statistics module.
import statistics
numbers = [10, 20, 30, 40, 50]
mean_value = statistics.mean(numbers)
print("Numbers:", numbers)
print("Mean =", mean_value)
Sample Output:
Numbers: [10, 20, 30, 40, 50]
Mean = 30
16. Python program to find the median of a list using statistics module.
import statistics
numbers = [10, 20, 30, 40, 50]
median_value = statistics.median(numbers)
print("Numbers:", numbers)
print("Median =", median_value)
Sample Output:
Numbers: [10, 20, 30, 40, 50]
Median = 30
17. Python program to find the mode of a list using statistics module.
import statistics
numbers = [10, 20, 20, 30, 40, 20]
mode_value = statistics.mode(numbers)
print("Numbers:", numbers)
print("Mode =", mode_value)
Sample Output:
Numbers: [10, 20, 20, 30, 40, 20]
Mode = 20
18. Python program to find the variance using statistics module.
import statistics
numbers = [10, 20, 30, 40, 50]
variance_value = statistics.variance(numbers)
print("Numbers:", numbers)
print("Variance =", variance_value)
Sample Output:
Numbers: [10, 20, 30, 40, 50]
Variance = 250
19. Python program to find the standard deviation using statistics module.
import statistics
numbers = [10, 20, 30, 40, 50]
std_dev = statistics.stdev(numbers)
print("Numbers:", numbers)
print("Standard Deviation =", std_dev)
Sample Output:
Numbers: [10, 20, 30, 40, 50]
Standard Deviation = 15.811388300841896