Hands-On Exercise-I (Elements of Python Programming)
Hands-On Exercise-I (Elements of Python Programming)
2. Write a Python program that displays your name and address on the screen as below:
+---------------------------------------------------------+
| #### |
| #### |
| #### |
| |
| |
| Biswanath Dash |
| H.N:109, Baramunda |
| Bhubaneswar |
| |
+-------------------------------------------------------------------------------------------------------+
3. Write a Python program to display your initials on the screen in block letters as shown. For
example, the name Tapan Kumar
TTTTTTTT K K
T K K
T K K
T K
T K K
T K K
T K K
4. Write a Python program to print an equilateral triangle using the star ' * '.
*
**
***
****
*****
5. Write a Python program that stores your Regd. No and year of admission into two variables, and
displays their values on the screen.
7. Write a Python program to exchange the values of two variables of integer type A and B using
the third temporary variable C.
8. Write a Python program to exchange the values of two variables of integer type A and B without
using a third temporary variable.
9. Write a Python program that reads a Celsius degree in a double value from the console, then
converts it to Fahrenheit and displays the result. The formula for the conversion is as follows:
fahrenheit = (9 / 5) * celsius + 32
10. Write a Python program that reads in the radius and length of a cylinder and computes the area
and volume using the following formulas:
11. Write a Python program that reads a number in feet, converts it to meters, and displays the result.
One foot is 0.305 meters.
Here is a sample run:
13. Average acceleration is defined as the change of velocity divided by the time taken to make the
change, as shown in the following formula:
𝑣 𝑣
𝑎=
𝑡
Write a Python program that prompts the user to enter the starting velocity v0 in meters/second,
the ending velocity v1 in meters/second, and the time span t in seconds, and displays the
average acceleration.
14. Body Mass Index (BMI) measures health on weight. It can be calculated by taking your weight
in kilograms and dividing it by the square of your height in meters. Write a Python program that
prompts the user to enter weight in pounds and height in inches and displays the BMI.
Note that one pound is 0.45359237 kilograms and one inch is 0.0254 meters.
15. Write a Python program that prompts the user to enter the side of a hexagon and displays its area.
The formula for computing the area of a hexagon is
3√3
𝐴𝑟𝑒𝑎 = 𝑥
2
where s is the length of a side.
Here is a sample run:
Enter the side: 5.5
The area of the hexagon is 78.5895
a b pow(a, b)
1 2 1
2 3 8
3 4 81
4 5 1024
5 6 15625
17. Write a Python program that prompts the user to enter two points (x1, y1) and (x2, y2) and
displays the distance between them. The formula for computing the distance is
(𝑥 − 𝑥 ) + (𝑦 − 𝑦 ) .
18. Write a Python program that prompts the user to enter three points (x1, y1), (x2, y2), (x3, y3) of
a triangle and displays its area. The formula for computing the area of a triangle is
19. Write a Python program that reads in investment amount, annual interest rate, and number of
years, and displays the future investment value using the following formula:
∗
futureInvestmentValue = investmentAmount x(1 + 𝑚𝑜𝑛𝑡𝑙𝑦𝐼𝑛𝑡𝑒𝑟𝑒𝑠𝑡𝑅𝑎𝑡𝑒)
For example, if you enter amount 1000, annual interest rate 3.25%, and number of years 1, the
future investment value is 1032.98.
20. If you have N eggs, then you have N//12 dozen eggs, with N%12 eggs left over. (This is essentially
the definition of the // and % operators for integers.) Write a Python program that asks the user
how many eggs she has and then tells the user how many dozen eggs she has and how many extra
eggs are left over. A gross of eggs is equal to 144 eggs. Extend your program so that it will tell
the user how many gross, how many dozen, and how many left over eggs she has. For example,
if the user says that she has 1342 eggs, and then your program would respond with
21. Write a Python program that prompts the user to enter the minutes (e.g., 1 billion), and displays
the number of years and days for the minutes.
For simplicity, assume a year has 365 days.
*****************