This repository has been archived by the owner on Jul 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
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
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() |
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
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 | ||
|
||
|