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 4 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
23 changes: 23 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,23 @@
def calculate_square(number):
return number ** 2
pratyusha-samidhapudi marked this conversation as resolved.
Show resolved Hide resolved

def main():
# 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()
14 changes: 14 additions & 0 deletions tests/FindSquare/test_square.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from square import calculate_square
def test_square_calculation():
from square import calculate_square

# 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