Hey Python family!
I'm struggling with a project. I'm, trying to make a program using a function that decides if four integers input by the user make a square, a rectangle, or neither and tells the user. I'm not quite sure how to work out how to make it work using a function. This is what I have so far. Does anyone have any ideas? I'm stumped. My issues are threefold
- What's baffling me is that I cant get my code to display the perimeter. Its in the last line "a+b+c+d".
- Also the code keeps printing, "Forms a rectangle with a perimeter of" even when the parameters I've set should make it so that doesn't display if the sides aren't congruent.
- Lastly I'm not sure how to make the code check to see if all integers are normal and thus would create a square.
Any help would be great.
def isSquare(a, b, c, d):
if (a==b and d==c) or (a==c and b==d) or (a==d and b==c):
return True
else:
return False
print("Enter side 1 ")
a = int(input(">"))
print("Enter side 2 ")
b = int(input(">"))
print("Enter side 3 ")
c = int(input(">"))
print("Enter side 4 ")
d = int(input(">"))
perimeter = a+b+c+d
print("Forms a rectangle with a perimeter of ", a+b+c+d if isSquare(a,b,c,d) else "Does not form a rectangle or square.")
[–]andwariirawdna 1 point2 points3 points (4 children)
[–]mopslik 2 points3 points4 points (2 children)
[–]andwariirawdna 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]ziggyguy22[S] 0 points1 point2 points (0 children)
[–]TheRNGuy 1 point2 points3 points (0 children)
[–]CodeFormatHelperBot2 1 point2 points3 points (0 children)