BASIC PROGRAMS-1
Problem Statement:
Write a Python program that prints the message “Hello, World!” to the console.
Objective:
To understand the basic syntax of a Python program and how to display output using the
print() function.
[Link] of Two Numbers
Write a program to take two integers a and b as input and calculate their sum.
Expression: sum = a + b
i/p: 3 4
o/p: The addition is 7
[Link] of Three Numbers
Write a program to take three integers a, b, and c as input and calculate their sum.
Expression: sum = a + b + c
i/p: 2 3 5
o/p: The addition is 10
Subtraction Problems
[Link] of Two Numbers
Write a program to take two integers a and b as input and calculate their difference (a - b).
Expression: difference = a - b
i/p: 10 4
o/p: The difference is 6
[Link] of Three Numbers
Write a program to take three integers a, b, and c as input and calculate the result of subtracting b
and c from a.
Expression: result = a - b - c
i/p: 20 5 3
o/p: The difference is 12
Multiplication Problems
[Link] of Two Numbers
Write a program to take two integers a and b as input and calculate their product.
Expression: product = a * b
i/p: 6 7
o/p: The product is 42
[Link] of Three Numbers
Write a program to take three integers a, b, and c as input and calculate their product.
Expression: product = a * b * c
i/p: 2 3 4
o/p: The product is 24
Division Problems
[Link] of Two Numbers
Write a program to take two integers a and b as input and calculate the quotient of a divided by
b.
Expression: quotient = a / b (consider both integer division and floating-point division)
i/p: 8 3
o/p:The quotient is 2.6666667
The integer quotient is 2
[Link] Result of Three Numbers
Write a program to take three integers a, b, and c as input and calculate the result of dividing a by
b and then by c.
Expression: result = a / b / c (consider both integer division and floating-point division)
i/p: 20 5 2
o/p:The result is 2.0
The integer result is 2
Combined Problems
[Link] Operations with Two Numbers
Write a program to take two integers a and b as input and calculate the sum, difference, product,
and quotient.
Expressions:
sum = a + b
difference = a - b
product = a * b
quotient = a / b (consider both integer division and floating-point division)
i/p: 12 4
o/p:
The sum is 16
The difference is 8
The product is 48
The quotient is 3
[Link] Operations with Three Numbers
Write a program to take three integers a, b, and c as input and calculate the sum, difference,
product, and result of dividing the sum of a and b by c.
Expressions:
sum = a + b + c
difference = a - b - c
product = a * b * c
result = (a + b) / c (consider both integer division and floating-point division)
i/p: 10 5 3
o/p:
The sum is 18
The difference is 2
The product is 150
The result is 5
Area Problems
[Link]
Write a program to take the length l and width w of a rectangle as input and calculate its area.
Expression: area = l * w
i/p: 5 4
o/p: The area is 20
[Link]
Write a program to take the base b and height h of a triangle as input and calculate its area.
Expression: area = 0.5 * b * h
i/p: 10 6
o/p: The area is 30
[Link]
Write a program to take the radius r of a circle as input and calculate its area.
Expression: area = 3.14 * r * r (use π ≈ 3.14) Or take π value from math module
i/p: 7
o/p: The area is 153.86
[Link]
Write a program to take the lengths of the two bases a and b, and height h of a trapezoid as input
and calculate its area.
Expression: area = 0.5 * (a + b) * h
i/p: 5 7 4
o/p: The area is 24
[Link]
Write a program to take the base b and height h of a parallelogram as input and calculate its area.
Expression: area = b * h
i/p: 8 6
o/p: The area is 48
Volume Problems
[Link]
Write a program to take the length l, width w, and height h of a cuboid as input and calculate its
volume.
Expression: volume = l * w * h
i/p: 4 5 6
o/p: The volume is 120
[Link]
Write a program to take the side length a of a cube as input and calculate its volume.
Expression: volume = a * a * a
i/p: 5
o/p: The volume is 125
[Link]
Write a program to take the radius r and height h of a cylinder as input and calculate its volume.
Expression: volume = 3.14 * r * r * h (use π ≈ 3.14)
i/p: 3 10
o/p: The volume is 282.6
[Link]
Write a program to take the radius r of a sphere as input and calculate its volume.
Expression: volume = (4.0 / 3.0) * 3.14 * r * r * r (use π ≈ 3.14)
i/p: 6
o/p: The volume is 904.32
[Link]
Write a program to take the radius r and height h of a cone as input and calculate its volume.
Expression: volume = (1.0 / 3.0) * 3.14 * r * r * h (use π ≈ 3.14)
i/p: 4 9
o/p: The volume is 150.72
Combined Problems
[Link] Area and Volume of a Cylinder
Write a program to take the radius r and height h of a cylinder as input and calculate both its
surface area and volume.
Expressions:
surface_area = 2 * 3.14 * r * (r + h) (use π ≈ 3.14)
volume = 3.14 * r * r * h
i/p: 3 7
o/p:
The surface area is 188.4
The volume is 197.82
[Link] Area and Volume of a Sphere
Write a program to take the radius r of a sphere as input and calculate both its surface area and
volume.
Expressions:
surface_area = 4 * 3.14 * r * r (use π ≈ 3.14)
volume = (4.0 / 3.0) * 3.14 * r * r * r
i/p: 5
o/p:
The surface area is 314
The volume is 523.33