w3resource

Python: Print the square and cube symbol in the area of a rectangle and volume of a cylinder

Python String: Exercise-43 with Solution

Write a Python program to print the square and cube symbols in the area of a rectangle and the volume of a cylinder.

Python String Exercises: Print the square and cube symbol in the area of a rectangle and volume of a cylinder

Sample Solution:

Python Code:

# Define the area and volume as floating-point numbers.
area = 1256.66
volume = 1254.725

# Define the number of decimals for formatting.
decimals = 2

# Print the area of the rectangle with formatting and the specified number of decimals.
print("The area of the rectangle is {0:.{1}f}cm\u00b2".format(area, decimals))

# Update the number of decimals for formatting.
decimals = 3

# Print the volume of the cylinder with formatting and the specified number of decimals.
print("The volume of the cylinder is {0:.{1}f}cm\u00b3".format(volume, decimals))

Sample Output:

The area of the rectangle is 1256.66cm²                                                                       
The volume of the cylinder is 1254.725cm³                      

Flowchart:

Flowchart: Print the square and cube symbol in the area of a rectangle and volume of a cylinder

Python Code Editor:

Previous: Write a python program to count repeated characters in a string.
Next: Write a Python program to print the index of the character in a string.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://198.211.115.131/python-exercises/string/python-data-type-string-exercise-43.php