Python Programs | IT Developer
IT Developer

Python Programs



Share with a Friend

Python Programs - Input and Output

Input radius and print area and circumference of a circle - Python Program

Example 1:
radius = float(input("Enter radius: ")) area = 3.14159 * radius * radius circumference = 2 * 3.14159 * radius print(f"Area = {area:.2f}") print(f"Circumference = {circumference:.2f}")

Output

 
OUTPUT  :
Enter radius: 3
Area = 28.27
Circumference = 18.85
Example 2:
import math # Prompt the user to enter the radius try: radius = float(input("Enter the radius of the circle: ")) except ValueError: print("Invalid input. Please enter a numerical value for the radius.") else: # Check if the radius is non-negative if radius >= 0: # Calculate the area area = math.pi * (radius ** 2) # Calculate the circumference circumference = 2 * math.pi * radius # Print the results print(f"The area of the circle is: {area:.2f}") print(f"The circumference of the circle is: {circumference:.2f}") else: print("Radius cannot be negative. Please enter a non-negative value.")

Output

 
OUTPUT  :
Enter the radius of the circle: 10
The area of the circle is: 314.16
The circumference of the circle is: 62.83