0% found this document useful (0 votes)
3 views2 pages

math module application

The document contains three Python programming tasks: calculating the area of a circle using its radius, computing the square root of a number, and finding the Greatest Common Divisor (GCD) of two numbers. Each task includes the necessary code snippets that utilize the math module for calculations. The programs prompt the user for input and display the results formatted to two decimal places.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

math module application

The document contains three Python programming tasks: calculating the area of a circle using its radius, computing the square root of a number, and finding the Greatest Common Divisor (GCD) of two numbers. Each task includes the necessary code snippets that utilize the math module for calculations. The programs prompt the user for input and display the results formatted to two decimal places.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Question 1: Calculate the Area of a Circle

Write a Python program that calculates the area of a circle given its radius. Use the math
module to access the value of π (pi).

import math

# Input: radius of the circle

radius = float(input("Enter the radius of the circle: "))

# Calculate area using the formula: area = π * r^2

area = math.pi * math.pow(radius, 2)

# Output the result

print(f"The area of the circle with radius {radius} is {area:.2f}")

Question 2: Compute the Square Root of a Number

Write a Python program that computes the square root of a given number using the math
module.

Answer:
import math
# Input: number to find the square root of

number = float(input("Enter a number to find its square root: "))

# Compute square root

square_root = math.sqrt(number)

# Output the result

print(f"The square root of {number} is {square_root:.2f}")


Question 3: Calculate the GCD of Two Numbers

Write a Python program that calculates the Greatest Common Divisor (GCD) of two numbers
using the math module.

Answer:

import math

# Input: two numbers

num1 = int(input("Enter the first number: "))

num2 = int(input("Enter the second number: "))

# Calculate GCD

gcd = math.gcd(num1, num2)

# Output the result

print(f"The GCD of {num1} and {num2} is {gcd}")

You might also like