Eid Salami
PART A: BASIC ARITHMETIC (5)
1. Write a Python program to find the sum, difference, product, quotient, and remainder of
two given numbers.
Input
First number: 10
Second number: 5
Output
Sum = 15
Difference = 5
Product = 50
Quotient = 2
Remainder = 0
2. Write a Python program to input the radius of a circle from the user and find the diameter,
circumference, and area of the circle.
Input
Enter radius: 10
Output
Diameter: 20 units
Circumference: 62.832 units
Area: 314.16 sq. units
3. Write a Python program to swap the values of two integer variables using extra variables.
Input
Enter value of a: 10
Enter value of b: 20
Output
Value of a is: 20
Value of b is: 10
4. Write a Python program to input a number of days from the user and convert it to years,
weeks and days.
Input
Enter days: 373
Output
373 days = 1 year/s, 1 week/s and 1 day/s
5. Write a Python program to input principle (amount), time, and rate (P, T, R) and find
Compound Interest.
Formula to calculate Compound Interest:
Input
Enter principal (amount): 1200
Enter time: 2
Enter interest rate: 5.4
Output
Compound Interest = 1333.099243
PART B: CONDITIONAL STATEMENT (15)
1. Write a Python program to find the maximum between two numbers using if else.
Input
Input number 1: 10
Input number 2: 20
Output
Maximum = 20
2. Write a Python program to find the maximum between three numbers using ladder if-else
or nested if.
Input
Input number 1: 10
Input number 2: 20
Input number 3: 15
Output
Maximum is: 20
3. Write a Python program to determine whether a number is even or odd.
Sample Input Sample Output
Enter a number: 24 24 is even.
Enter a number: 43 43 is odd.
4. Write a Python program to check leap year using if else.
Logic: If a year is exactly divisible by 4 and not divisible by 100, then it is a leap year. Or if a
year is exactly divisible by 400 then it is a leap year.
Input
Input year: 2004
Output
2004 is leap year.
5. Write a Python program to check whether a triangle is valid or not if angles are given using
if else.
Logic: A triangle is said to be a valid triangle if and only if the sum of its angles is 180 °.
Input
Input first angle: 60
Input second angle: 30
Input third angle: 90
Output
The triangle is valid.
6. Write a Python program to input cost price and selling price of a product and check profit
or loss.
Logic: Profit: SP > CP (where, SP is Selling Price and CP is Cost Price)
Loss: CP > SP
Input
Input cost price: 1000
Input selling price: 1500
Output
Profit: 500
7. Write a Python program to input marks of five subjects Physics, Chemistry, Biology,
Mathematics and Computer, calculate percentage and grade according to given conditions:
If percentage >= 90% : Grade A
If percentage >= 80% : Grade B
If percentage >= 70% : Grade C
If percentage >= 60% : Grade D
If percentage >= 40% : Grade E
If percentage < 40% : Grade F
Input
Marks of Physics: 95
Marks of Chemistry: 95
Marks of Biology: 97
Marks of Mathematics: 98
Marks of Computer: 90
Output
Percentage = 95.00%
Grade A
8. Write a Python program to input the day number (1-7) in a week and print the day of the
week name using a conditional statement. A week starts from Sunday for this problem.
Input
Input day number [1-7]: 2
Output
Monday
9. Write a Python program to check if a given character is a vowel or a consonant.
Input
Input a character: A
Output
A is a vowel.
10. Write a Python program to authenticate a user based on username and password.
Sample Input Sample Output
Username = ‘admin’ Authentication successful.
Password = ‘admin’
Username = ‘admin’ Authentication failed.
Password = ‘1234’
Username = ‘1234’ Authentication failed.
Password = ‘admin’
11. Write a Python program that takes BMI (Body Mass Index) as input and prints the
corresponding BMI category according to the following criteria:
● BMI < 18.5: Underweight
● 18.5 <= BMI < 25: Normal weight
● 25 <= BMI < 30: Overweight
● BMI >= 30: Obesity
Input
Enter BMI: 22.86
Output
Category: Normal weight
12. Write a Python program that takes a number as input and prints whether it's even and
divisible by 3.
Input
Enter a number: 12
Output
12 is even and divisible by 3.
13. Write a Python program to calculate the final price of an item after applying a discount
based on the purchase amount. If the purchase amount is greater than 100 then 10%
discount will be applied otherwise not.
Sample Input Sample Output
Enter the purchase amount: 120 Final price after discount: 108
Enter purchase amount: 90 Final price (No discount): 90
14. Write a program that simulates a traffic light. It takes the color of the traffic light as input
and outputs the action to be taken.
Sample Input Sample Output
Enter the color of the traffic light: red Stop
Enter the color of the traffic light: yellow Proceed with caution
Enter the color of the traffic light: green Go
Enter the color of the traffic light: white Invalid color
15. Write a program that classifies temperatures into hot, warm, or cold based on the user
input according to the following criteria:
● Temperature >= 30: Hot
● 20 <= Temperature < 30: Warm
● Temperature < 20: Cold
Sample Input Sample Output
Etner the temperature: 35 Hot
Etner the temperature: 25 Warm
Etner the temperature: 18 Cold
PART C: LOOP (10)
1. Write a Python program to print all natural numbers from 1 to n using for loop.
Input
Input N: 10
Output
Natural numbers from 1-10: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10.
2. Write a Python program to print all natural numbers in reverse from n to 1 using for loop.
Input
Input N: 10
Output
Natural numbers from 10-1 in reverse: 10, 9, 8, 7, 6, 5, 4, 3, 2, 1.
3. Write a program to calculate the sum of all numbers from 1 to n.
Input
Input a number: 5
Output
Sum of numbers from 1 to 5 is 15
4. Write a program to calculate the factorial of a number.
Input
Input a number: 4
Output
Factorial of 4 is 24
5. Write a program to print all even numbers between 1 and n.
Input
Input a number: 10
Output
Even numbers between 1 and 10: 2, 4, 6, 8, 10
6. Write a program to print the multiplication table of a given number.
Input
Input a number: 5
Output
Multiplication table of 5:
5x1=5
5 x 2 = 10
5 x 3 = 15
5 x 4 = 20
5 x 5 = 25
5 x 6 = 30
5 x 7 = 35
5 x 8 = 40
5 x 9 = 45
5 x 10 = 50
7. Write a program to count the number of digits in a given number.
Input
Input a number: 12345
Output
Number of digits in 12345 is 5
8. Write a program to print all even numbers between 1 and a given number using a loop.
Input
Input a number: 10
Output
Even numbers between 1 to 10 are: 2 4 6 8 10
9. Write a program to count the number of vowels and consonants in a given string using a
loop.
Input
Input a string: Hello
Output
Vowel: 2, Consonants: 3
10. Write a program to count the occurrences of a specific character in a given string using a
loop.
Input
Enter a string: hello
Enter a character: l
Output
Occurrence of l is: 2
PART D: LIST (10)
1. You need to create a list of your favorite fruits.
fruits = ["apple", "banana", "orange", "mango"]
Iterate this list, printing each fruit on a new line.
Output
apple
banana
orange
mango
2. Create a list with the names of your friends.
friends = ["Ratul", "Shuvo", "Ashik", "Rabbi", "Shakib"]
Check if a specific name exists in the list, and print a message accordingly.
Input
Suvo
Output
Suvo is not found in the list.
Input
Ashik
Output
Ashik is found in the list.
3. Insert a new name "Robin” at the 3rd position of the list of friends and print the new
update list.
Input
Robin
Output
Updated List: ["Ratul", "Shuvo", "Robin", "Ashik", "Rabbi", "Shakib"]
4. Create a list of numbers,
numbers = [5, 18, 2, 9, 25, 32, 23, 65, 4, 3]
Find the maximum, minimum, and average and print them.
Output
Maximum: 65
Minimum: 2
Average: 18.6
5. Iterate the list and multiply all the odd numbers and print the result:
numbers = [5, 18, 2, 9, 25, 32, 23, 65, 4, 3]