Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
7 views

Hands-On Exercise-I (Elements of Python Programming)

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Hands-On Exercise-I (Elements of Python Programming)

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Hands-on Exercise-I

(Elements of Python Programming)


1. Write a Python program to display the following messages.
Hello World!
Hello Again
I like typing this.
This is fun.
Yay! Printing.
I'd much rather you 'not'.
I "said" do not touch this.

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.

My Regd. No is 221123142 and I have been admitted to B. Tech, in 2022.


6. Let us have two values 113, 2.71828. Then, declare two different variables to hold the given
values. Write the Python program to display the values of these two variables on the screen, one
per line.

This is room # 113


e is close to 2.71828

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

Here is a sample run:


Enter a degree in Celsius: 43.0
43.0 Celsius is 109.4 Fahrenheit

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:

area = radius * radius * π


volume = area * length

Here is a sample run:


Enter the radius and length of a cylinder: 5.5 12
The area is 95.0331
The volume is 1140.4

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:

Enter a value for feet: 16.5


16.5 feet is 5.0325 meters
12. Write a Python program that reads an integer between 0 and 1000 and adds all the digits in the
integer. For example, if an integer is 932, the sum of all its digits is 14.

Here is a sample run:


Enter a number between 0 and 1000: 999
The sum of the digits is 27

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.

Here is a sample run:


Enter v0, v1, and t: 5.5 50.9 4.5
The average acceleration is 10.0889

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.

Here is a sample run:


Enter weight in pounds: 95.5
Enter height in inches: 50
BMI is 26.8573

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

16. Write a Python program that displays the following table.

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
(𝑥 − 𝑥 ) + (𝑦 − 𝑦 ) .

Here is a sample run:


Enter x1 and y1: 1.5 -3.4
Enter x2 and y2: 4 5
The distance between the two points is 8.764131445842194

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

s = (side1 + side2 + side3)/2;


𝑎𝑟𝑒𝑎 = 𝑠 ∗ (𝑠 − 𝑎) ∗ (𝑠 − 𝑏) ∗ (𝑠 − 𝑐)

Here is a sample run:


Enter three points for a triangle: 1.5 -3.4 4.6 5 9.5 -3.4
The area of the triangle is 33.6

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.

Here is a sample run:


Enter investment amount: 1000.56
Enter annual interest rate in percentage: 4.25
Enter number of years: 1
Accumulated value is $1043.92

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

Your number of eggs is 9 gross, 3 dozen, and 10.

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.

Here is a sample run:


Enter the number of minutes: 1000000000
1000000000 minutes is approximately 1902 years and 214 days

*****************

You might also like