{"id":16977,"date":"2021-08-12T09:25:33","date_gmt":"2021-08-12T03:55:33","guid":{"rendered":"https:\/\/python-programs.com\/?p=16977"},"modified":"2021-11-22T18:38:30","modified_gmt":"2021-11-22T13:08:30","slug":"python-program-to-calculate-surface-area-and-volume-of-a-cylinder","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-calculate-surface-area-and-volume-of-a-cylinder\/","title":{"rendered":"Python Program to Calculate Surface Area and Volume of a Cylinder"},"content":{"rendered":"
In the previous article, we have discussed Python Program to Check Pronic Number or Not<\/a> A cylinder is a closed geometrical solid shape with two parallel bases joined by a curved surface. The following is the formula for calculating<\/p>\n where\u00a0 r = radius of the base circle<\/p>\n h = height of the curved surface<\/p>\n Given the radius and height of the cylinder, and the task is to calculate the surface area and volume of the given cylinder.<\/p>\n Examples:<\/strong><\/p>\n Example 1:<\/strong><\/p>\n Input:\u00a0<\/strong><\/p>\n Output:<\/strong><\/p>\n Example 2:<\/strong><\/p>\n Input:\u00a0<\/strong><\/p>\n Output:<\/strong><\/p>\n Below are the ways to calculate the surface area and volume of the given cylinder.<\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Explore more instances related to python concepts from\u00a0Python Programming Examples<\/a>\u00a0Guide and get promoted from beginner to professional programmer level in Python Programming Language.<\/p>\n <\/p>\n","protected":false},"excerpt":{"rendered":" In the previous article, we have discussed Python Program to Check Pronic Number or Not Cylinder : A cylinder is a closed geometrical solid shape with two parallel bases joined by a curved surface. The bases are circular in shape. The following is the formula for calculating The area of a cylinder = 2\u03c0r(r+h) The …<\/p>\n
\nCylinder :<\/strong><\/p>\n
\nThe bases are circular in shape.<\/p>\n\n
Given radius = 2.5\r\nGiven height = 3.5<\/pre>\n
The surface area of a given cylinder = 137.44467859455347\r\nThe volume of a given cylinder = 68.72233929727673<\/pre>\n
Given radius = 7\r\nGiven height = 1.5<\/pre>\n
The surface area of a given cylinder = 461.81412007769956\r\nThe volume of a given cylinder = 230.90706003884978<\/pre>\n
Program to Calculate Surface Area and Volume of a Cylinder<\/h2>\n
\n
Method #1: Using Mathematical Formula (Static Input)<\/h3>\n
\n
# Import math module using the import keyword.\r\nimport math\r\n# Give the radius as static input and store it in a variable.\r\ngvn_radius = 4\r\n# Give the height as static input and store it in another variable.\r\ngvn_heigt = 7\r\n# Calculate the surface area of the given cylinder using the above given mathematical\r\n# formula, math.pi () method and store it in another variable.\r\nsurfc_area = 2*math.pi*pow(gvn_radius, 2)*gvn_heigt\r\n# Calculate the volume of the given cylinder using the above given mathematical formula,\r\n# math.pi () method and store it in another variable.\r\nvol = math.pi*pow(gvn_radius, 2)*gvn_heigt\r\n# Print the surface area of the given cylinder.\r\nprint(\"The surface area of a given cylinder =\", surfc_area)\r\n# Print the volume of the given cylinder.\r\nprint(\"The volume of a given cylinder =\", vol)<\/pre>\n
The surface area of a given cylinder = 703.7167544041137\r\nThe volume of a given cylinder = 351.85837720205683<\/pre>\n
Method #2: Using Mathematical Formula (User Input)<\/h3>\n
\n
# Import math module using the import keyword.\r\nimport math\r\n# Give the radius as user input using the float(input())function and store it in a variable.\r\ngvn_radius = float(input(\"Enter some random number = \"))\r\n# Give the height as user input using the float(input())function store it in another variable.\r\ngvn_heigt = float(input(\"Enter some random number = \"))\r\n# Calculate the surface area of the given cylinder using the above given mathematical\r\n# formula, math.pi () method and store it in another variable.\r\nsurfc_area = 2*math.pi*pow(gvn_radius, 2)*gvn_heigt\r\n# Calculate the volume of the given cylinder using the above given mathematical formula,\r\n# math.pi () method and store it in another variable.\r\nvol = math.pi*pow(gvn_radius, 2)*gvn_heigt\r\n# Print the surface area of the given cylinder.\r\nprint(\"The surface area of a given cylinder =\", surfc_area)\r\n# Print the volume of the given cylinder.\r\nprint(\"The volume of a given cylinder =\", vol)\r\n<\/pre>\n
Enter some random number = 5.5\r\nEnter some random number = 8\r\nThe surface area of a given cylinder = 1520.53084433746\r\nThe volume of a given cylinder = 760.26542216873<\/pre>\n
\n