Leela Soft 1000 MCQ Programs Madhu
i = i + 1
sum1 = sum1 + f
num = num // 10
if(sum1 == temp):
print("The number is a strong number")
else:
print("The number is not a strong number")
Program Explanation
1. User must enter the number and store it in a variable.
2. A copy of the original number is made as the original value will get altered in the later
course of the program.
3. Using a while loop, each of the digits of the numbers is obtained.
4. Then the other while loop is used to find the factorial of the individual digits and store it
in a sum variable.
5. If the sum of the factorial of the digits in a number is equal to the original number, the
number is a strong number.
6. The final result is printed.
Runtime Test Cases
Case 1:
Enter a number:145
The number is a strong number.
Case 2:
Enter a number:234
The number is not a strong number.
Python Program to Find the LCM of Two Numbers
Problem Description
The program takes two numbers and prints the LCM of two numbers.
Problem Solution
1. Take in both the integers and store it in separate variables.
2. Find which of the integer among the two is smaller and store it in a separate variable.
3. Use a while loop whose condition is always True until break is used.
4. Use an if statement to check if both the numbers are divisible by the minimum number
and increment otherwise.
5. Print the final LCM.
6. Exit.
www.leelasoft.com Cell: 78 42 66 47 66
Leela Soft 1000 MCQ Programs Madhu
Program/Source Code
Here is source code of the Python Program to find the LCM of two numbers. The program output
is also shown below.
a = int(input("Enter the first number:"))
b = int(input("Enter the second number:"))
if(a > b):
min1 = a
else:
min1 = b
while(1):
if(min1 % a == 0 and min1 % b == 0):
print("LCM is:", min1)
break
min1 = min1 + 1
Program Explanation
1. User must enter both the numbers and store it in separate variables.
2. An if statement is used to find out which of the numbers is smaller and store in a minimum
variable.
3. Then a while loop is used whose condition is always true (or 1) unless break is used.
4. Then an if statement within the loop is used to check whether the value in the minimum
variable is divisible by both the numbers.
5. If it is divisible, break statement breaks out of the loop.
6. If it is not divisible, the value in the minimum variable is incremented.
7. The final LCM is printed.
Runtime Test Cases
Case 1:
Enter the first number:5
Enter the second number:3
LCM is: 15
Case 2:
Enter the first number:15
Enter the second number:20
LCM is: 60
Python Program to Find the GCD of Two Numbers
Problem Description
The program takes two numbers and prints the GCD of two numbers.
www.leelasoft.com Cell: 78 42 66 47 66
Leela Soft 1000 MCQ Programs Madhu
Problem Solution
1. Import the fractions module.
2. Take in both the integers and store it in separate variables.
3. Use the in-built function to find the GCD of both the numbers.
4. Print the GCD.
5. Exit.
Program/Source Code
Here is source code of the Python Program to find the GCD of two numbers. The program output
is also shown below.
import fractions
a = int(input("Enter the first number:"))
b = int(input("Enter the second number:"))
print("The GCD of the two numbers is", fractions.gcd(a, b))
Program Explanation
1. Import the fractions module.
2. User must enter both the numbers and store it in separate variables.
3. The in-built function of fractions.gcd(a,b) is used where a and b are the variables
containing the integer values.
4. The final GCD is printed.
Runtime Test Cases
Case 1:
Enter the first number:15
Enter the second number:5
The GCD of the two numbers is 5
Case 2:
Enter the first number:105
Enter the second number:222
The GCD of the two numbers is 3
Python Program to Compute a Polynomial Equation given that the Coefficients of the
Polynomial are stored in a List
Problem Description
The program takes the coefficients of the polynomial equation and the value of x and gives the
value of the polynomial.
www.leelasoft.com Cell: 78 42 66 47 66
Leela Soft 1000 MCQ Programs Madhu
Problem Solution
1. Import the math module.
2. Take in the coefficients of the polynomial equation and store it in a list.
3. Take in the value of x.
4. Use a for loop and while loop to compute the value of the polynomial expression for the
first three terms and store it in a sum variable.
5. Add the fourth term to the sum variable.
6. Print the computed value.
7. Exit.
Program/Source Code
Here is source code of the Python Program to compute a polynomial equation given that the
coefficients of the polynomial are stored in a list. The program output is also shown below.
import math
print("Enter the coefficients of the form ax^3 + bx^2 + cx + d")
lst = []
for i in range(0, 4):
a = int(input("Enter coefficient:"))
lst.append(a)
x = int(input("Enter the value of x:"))
sum1 = 0
j = 3
for i in range(0, 3):
while(j > 0):
sum1 = sum1 + (lst[i] * math.pow(x, j))
break
j = j - 1
sum1 = sum1 + lst[3]
print("The value of the polynomial is:", sum1)
Program Explanation
1. The math module is imported.
2. User must enter the coefficients of the polynomial which is stored in a list.
3. User must also enter the value of x.
4. The value of i ranges from 0 to 2 using the for loop which is used to access the coefficients
in the list.
5. The value of j ranges from 3 to 1, which is used to determine the power for the value of
x.
6. The value of the first three terms is computed this way.
7. The last term is added to the final sum.
8. The final computed value is printed.
www.leelasoft.com Cell: 78 42 66 47 66
Leela Soft 1000 MCQ Programs Madhu
Runtime Test Cases
Case 1:
Enter the coefficients of the form ax^3 + bx^2 + cx + d
Enter coefficient:3
Enter coefficient:4
Enter coefficient:5
Enter coefficient:6
Enter the value of x:2
The value of the polynomial is: 56.0
Case 2:
Enter the coefficients of the form ax^3 + bx^2 + cx + d
Enter coefficient:2
Enter coefficient:5
Enter coefficient:6
Enter coefficient:3
Enter the value of x:1
The value of the polynomial is: 16.0
Python Program to Check If Two Numbers are Amicable Numbers
Problem Description
The program takes two numbers and checks if they are amicable numbers.
Problem Solution
1. Take in both the integers and store it in separate variables.
2. Find the sum of the proper divisors of both the numbers.
3. Check if the sum of the proper divisors is equal to the opposite numbers.
4. If they are equal, they are amicable numbers.
5. Print the final result.
6. Exit.
Program/Source Code
Here is the source code of the Python Program to check if two numbers are amicable numbers.
The program output is also shown below.
x = int(input('Enter number 1: '))
y = int(input('Enter number 2: '))
sum1 = 0
sum2 = 0
for i in range(1, x):
www.leelasoft.com Cell: 78 42 66 47 66
Leela Soft 1000 MCQ Programs Madhu
if x % i == 0:
sum1 += i
for j in range(1, y):
if y % j == 0:
sum2 += j
if(sum1 == y and sum2 == x):
print('Amicable!')
else:
print('Not Amicable!')
Program Explanation
1. User must enter both the numbers and store it in separate variables.
2. Using a for loop and an if statement, find the proper divisors of both the numbers.
3. Find the sum of the proper divisors of both the numbers.
4. The if statement is used to check if the sum of proper divisors of the number is equal to
the other number and vice-versa.
5. If it is equal, both the numbers are amicable numbers.
6. The final result is printed.
Runtime Test Cases
Case 1:
Enter number 1: 220
Enter number 2: 284
Amicable!
Case 2:
Enter number 1: 349
Enter number 2: 234
Not Amicable!
Python Program to Find the Area of a Triangle Given All Three Sides
Problem Description
The program takes three sides of a triangle and prints the area formed by all three sides.
Problem Solution
1. Take in all the three sides of the triangle and store it in three separate variables.
2. Then using the Heron’s formula, compute the area of the triangle.
3. Print the area of the triangle.
4. Exit.
www.leelasoft.com Cell: 78 42 66 47 66
Leela Soft 1000 MCQ Programs Madhu
Program/Source Code
Here is source code of the Python Program to find the area of a triangle given all three sides. The
program output is also shown below.
import math
a = int(input("Enter first side: "))
b = int(input("Enter second side: "))
c = int(input("Enter third side: "))
s = (a + b + c) / 2
area = math.sqrt(s * (s - a) * (s - b) * (s - c))
print("Area of the triangle is: ", round(area, 2))
Program Explanation
1. User must enter all three numbers and store it in separate variables.
2. First the value of s is found out which is equal to (a+b+c)/2
3. Then the Heron’s formula is applied to determine the area of the triangle formed by all
three sides.
4. Then the area of the triangle is printed.
Runtime Test Cases
Case 1:
Enter first side: 15
Enter second side: 9
Enter third side: 7
Area of the triangle is: 20.69
Case 2:
Enter first side: 5
Enter second side: 6
Enter third side: 7
Area of the triangle is: 14.7
Python Program to Find the Gravitational Force Acting Between Two Objects
Problem Description
The program takes the masses of two objects and the distance between them to determine the
gravitational force acting between the objects.
Problem Solution
1. Take in both the masses and the distance between the masses and store it in separate
variables.
www.leelasoft.com Cell: 78 42 66 47 66
Leela Soft 1000 MCQ Programs Madhu
2. Initialize one of the variables to the value of gravitational constant, G.
3. The the formula is used to determine the force acting between the masses.
4. Rounding off up-to two decimal places, print the value of the force.
5. Exit.
Program/Source Code
Here is source code of the Python Program to find the gravitational force acting between two
objects. The program output is also shown below.
m1 = float(input("Enter the first mass: "))
m2 = float(input("Enter the second mass: "))
r = float(input("Enter the distance between the centres of the masses: "))
G = 6.673 * (10 ** -11)
f = (G * m1 * m2) / (r ** 2)
print("Hence, the gravitational force is: ", round(f, 2), "N")
Program Explanation
1. User must enter the values for both the masses and the distance between the masses and
store it in separate variables.
2. One of the variables is initialised to the value of gravitational constant (G) which is equal
to 6.673*(10**-11).
3. Then the formula: f=(G*m1*m2)/(r**2), where m1 and m2 are the masses and r is the
distance between them, is used to determine the magnitude of force acting between the masses.
4. The force calculated is rounded up-to 2 decimal places and printed.
Runtime Test Cases
Case 1:
Enter the first mass: 1000000
Enter the second mass: 500000
Enter the distance between the centres of the masses: 20
Hence, the gravitational force is: 0.08 N
Case 2:
Enter the first mass: 90000000
Enter the second mass: 7000000
Enter the distance between the centres of the masses: 20
Hence, the gravitational force is: 105.1 N
www.leelasoft.com Cell: 78 42 66 47 66
Leela Soft 1000 MCQ Programs Madhu
Python Program to Check if a Number is a Prime Number
Problem Description
The program takes in a number and checks if it is a prime number.
Problem Solution
1. Take in the number to be checked and store it in a variable.
2. Initialize the count variable to 0.
3. Let the for loop range from 2 to half of the number (excluding 1 and the number itself).
4. Then find the number of divisors using the if statement and increment the count variable
each time.
5. If the number of divisors is lesser than or equal to 0, the number is prime.
6. Print the final result.
7. Exit.
Program/Source Code
Here is source code of the Python Program to check if a number is a prime number. The program
output is also shown below.
a = int(input("Enter number: "))
k = 0
for i in range(2, a // 2 + 1):
if(a % i == 0):
k = k + 1
if(k <= 0):
print("Number is prime")
else:
print("Number isn't prime")
Program Explanation
1. User must enter the number to be checked and store it in a different variable.
2. The count variable is first initialized to 0.
3. The for loop ranges from 2 to the half of the number so 1 and the number itself aren’t
counted as divisors.
4. The if statement then checks for the divisors of the number if the remainder is equal to
0.
5. The count variable counts the number of divisors and if the count is lesser or equal to 0,
the number is a prime number.
6. If the count is greater than 0, the number isn’t prime.
7. The final result is printed.
www.leelasoft.com Cell: 78 42 66 47 66
Leela Soft 1000 MCQ Programs Madhu
Runtime Test Cases
Case 1:
Enter number: 7
Number is prime
Case 2:
Enter number: 35
Number isn't prime
Python Program to Print all the Prime Numbers within a Given Range
Problem Description
The program takes in the upper limit and prints all prime numbers within the given range.
Problem Solution
1. Take in the upper limit for the range and store it in a variable.
2. Let the first for loop range from 2 to the upper limit.
3. Initialize the count variable to 0.
4. Let the second for loop range from 2 to half of the number (excluding 1 and the number
itself).
5. Then find the number of divisors using the if statement and increment the count variable
each time.
6. If the number of divisors is lesser than or equal to 0, the number is prime.
7. Print the final result.
8. Exit.
Program/Source Code
Here is source code of the Python Program to check if a number is a prime number. The program
output is also shown below.
r = int(input("Enter upper limit: "))
for a in range(2, r + 1):
k = 0
for i in range(2, a // 2 + 1):
if(a % i == 0):
k = k + 1
if(k <= 0):
print(a)
Program Explanation
1. User must enter the upper limit of the range and store it in a different variable.
www.leelasoft.com Cell: 78 42 66 47 66