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

Commit

Permalink
Resolve #69 (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
shorodilov authored Nov 27, 2023
2 parents 8f7cc02 + 4752898 commit 457b071
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/FindSquare/square.py
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

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


0 comments on commit 457b071

Please sign in to comment.