Write a Python program to calculate surface volume and area of a sphere


This Python code calculates and prints the surface area and volume of a sphere based on user input. Here's an explanation of each part of the code:

  • import math: This line imports the math module, which provides various mathematical functions and constants.
  • radian = float(input("Enter the Radius of Sphere :")): This line prompts the user to enter the radius of the sphere and stores it as a floating-point number in the variable radian.
  • sur_area = 4 * math.pi * (radian ** 2): This line calculates the surface area of the sphere using the formula for the surface area of a sphere, which is 4πr^2, where π is a constant (math.pi) and r is the radius. The result is stored in the variable sur_area.
  • volume = (4/3) * math.pi * (radian ** 3): This line calculates the volume of the sphere using the formula for the volume of a sphere, which is (4/3)πr^3. The result is stored in the variable volume.
  • The code then uses print statements to display the calculated values of the surface area and volume of the sphere, along with appropriate units of measurement (square units for surface area and cubic units for volume).

Source Code

import math
radian = float(input("Enter the Radius of Sphere :"))
sur_area = 4 * math.pi * (radian **2)
volume = (4/3) * math.pi * (radian ** 3)
print("Surface Area of the Sphere : ", sur_area)
print("Volume of the Sphere : ", volume)

Output

Enter the Radius of Sphere :2.3
Surface Area of the Sphere :  66.47610054996001
Volume of the Sphere :  50.965010421636

Example Programs