Skip to content
This repository has been archived by the owner on Jul 2, 2024. It is now read-only.

Solved 'Find the square of a number' #117

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions src/FindSquare/square.py
pratyusha-samidhapudi marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
def calculate_square(number):
"""
Calculate the square value of a given number.

Parameters:
- number (float): The input number for which the square value is calculated.

Returns:
- float: The square value of the input number.
"""
return number ** 2
pratyusha-samidhapudi marked this conversation as resolved.
Show resolved Hide resolved

def main():
"""
The main function of the program. It takes user input, calculates the square value,
and prints the result.

Usage:
- Run this script to input a number and get its square value.
"""
# Ask the user for a number
user_input = input("Enter a number: ")

try:
# To cast the input to a numeric type
number = float(user_input)

# Calculate the square value
square_value = calculate_square(number)

# Print out the result
print(f"The square value of {number} is: {square_value}")

except ValueError:
# Handle the case where the input cannot be cast to a numeric type
print("Invalid input. Please enter a valid number.")

if __name__ == "__main__":
main()
13 changes: 13 additions & 0 deletions tests/FindSquare/test_square.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from FindSquare.square import calculate_square
def test_square_calculation():

# Test with a positive number
assert calculate_square(4) == 16

# Test with a negative number
assert calculate_square(-3) == 9

# Test with a decimal number
assert calculate_square(2.5) == 6.25


Loading