0% found this document useful (0 votes)
9 views

Python Code

Python

Uploaded by

Laxmi Rajput
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Python Code

Python

Uploaded by

Laxmi Rajput
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

import random

import math

# Function to generate random integers


def random_integer(min_value, max_value):
return random.randint(min_value, max_value)

# Function to generate random floats


def random_float(min_value, max_value):
return random.uniform(min_value, max_value)

# Function to calculate area of a circle


def circle_area(radius):
return math.pi * radius ** 2

# Function to calculate area of a rectangle


def rectangle_area(length, width):
return length * width

# Function to calculate area of a triangle


def triangle_area(base, height):
return 0.5 * base * height

# Function to calculate volume of a sphere


def sphere_volume(radius):
return (4/3) * math.pi * radius ** 3

# Function to calculate volume of a cube


def cube_volume(side_length):
return side_length ** 3

# Function to calculate volume of a rectangular prism


def rectangular_prism_volume(length, width, height):
return length * width * height

# Example usage:

# Generate random dimensions


radius = random_float(1, 10)
length = random_integer(1, 10)
width = random_integer(1, 10)
height = random_integer(1, 10)
side_length = random_integer(1, 10)
base = random_float(1, 10)

# Calculate areas
circle_area_result = circle_area(radius)
rectangle_area_result = rectangle_area(length, width)
triangle_area_result = triangle_area(base, height)

# Calculate volumes
sphere_volume_result = sphere_volume(radius)
cube_volume_result = cube_volume(side_length)
rectangular_prism_volume_result = rectangular_prism_volume(length, width, height)

# Print results
print(f"Random Radius: {radius}")
print(f"Circle Area: {circle_area_result}")
print(f"Random Length: {length}, Random Width: {width}")
print(f"Rectangle Area: {rectangle_area_result}")
print(f"Random Base: {base}, Random Height: {height}")
print(f"Triangle Area: {triangle_area_result}")
print(f"Sphere Volume: {sphere_volume_result}")
print(f"Cube Volume: {cube_volume_result}")
print(f"Rectangular Prism Volume: {rectangular_prism_volume_result}")

Random Radius: 8.993783165078973


Circle Area: 254.11757262780557
Random Length: 2, Random Width: 4
Rectangle Area: 8
Random Base: 4.8155822382355415, Random Height: 6
Triangle Area: 14.446746714706624
Sphere Volume: 3047.304462200921
Cube Volume: 27
Rectangular Prism Volume: 48

You might also like