Python: Print the square and cube symbol in the area of a rectangle and volume of a cylinder
Python String: Exercise-43 with Solution
Print area (rectangle) and volume (cylinder).
Write a Python program to print the square and cube symbols in the area of a rectangle and the 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:
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.
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://www.w3resource.com/python-exercises/string/python-data-type-string-exercise-43.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics