Python: Print the square and cube symbol in the area of a rectangle and volume of a cylinder
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:

For more Practice: Solve these Related Problems:
- Write a Python program to calculate and display the area of a rectangle and the volume of a cylinder using given dimensions.
- Write a Python program to accept user input for rectangle dimensions and cylinder dimensions, then print formatted results with units.
- Write a Python program to implement functions for rectangle area and cylinder volume, and display the outputs with appropriate symbols.
- Write a Python program to format the calculated area and volume to two decimal places and include unit labels in the output.
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.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics