Last active
March 26, 2024 23:47
-
-
Save joreilly86/b8acdcd630c8f110df6bce4f019bd088 to your computer and use it in GitHub Desktop.
Sample code from Substack Post
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ========================================================== | |
# Prepare Pseudocode for Calculating Concrete Volume | |
# ========================================================== | |
FUNCTION calculate_concrete_volume(length, width, depth) | |
# Calculate the area of the floor slab | |
area = length * width | |
# Calculate the volume of concrete required | |
volume = area * depth | |
# Return the calculated volume | |
RETURN volume | |
END FUNCTION | |
# ========================================================== | |
# Python Implementation of Concrete Volume Calculation | |
# ========================================================== | |
def calculate_concrete_volume(length, width, thickness): | |
""" | |
Calculates the volume of concrete required for a floor slab. | |
Args: | |
length (float): Length of the slab in meters. | |
width (float): Width of the slab in meters. | |
thickness (float): Thickness of the slab in meters. | |
Returns: | |
float: Total volume of concrete required in cubic meters. | |
""" | |
# Calculate the area of the slab | |
area = length * width | |
# Calculate the base volume required | |
base_volume = area * thickness | |
# Add 5% surplus for spillage and uneven surfaces | |
surplus_volume = base_volume * 0.05 | |
total_volume = base_volume + surplus_volume | |
# Return the total required concrete volume | |
return total_volume | |
# Example usage | |
slab_length = 10.0 # meters | |
slab_width = 8.0 # meters | |
slab_thickness = 0.2 # meters | |
required_volume = calculate_concrete_volume(slab_length, slab_width, slab_thickness) | |
print(f"Volume of concrete required: {required_volume} cubic meters") | |
# ========================================================== | |
# Basic Function for Stress Calculation | |
# ========================================================== | |
def calculate_stress(force, area): | |
""" | |
Calculates stress based on force and area. | |
Args: | |
force (float): Force applied in Newtons. | |
area (float): Area in square meters. | |
Returns: | |
float: Stress in Pascals. Returns a string if area is invalid. | |
""" | |
if area <= 0: # Check if the input area is positive | |
return "Invalid area. Area must be greater than zero." | |
return force / area | |
# Example usage | |
force = 100 # in Newtons | |
area = 0.5 # in square meters | |
stress = calculate_stress(force, area) | |
print(f"Stress: {stress} Pascals") | |
# ========================================================== | |
# Function Basics - Demonstrating a Simple Message Function | |
# ========================================================== | |
def truth(): | |
""" | |
Prints a message about Flocode. | |
""" | |
print("Flocode makes learning Python a little easier!") | |
# Test it out! | |
truth() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment