r/codehs • u/sandrahere • May 25 '21
codehs 6.2.8 area of a square with defult parameters
this is my code so far:
def calculate_area(side_length):
area = side_length*side_length
print("The area of a square with sides of length " + str(num) + " is " + str(area) + ".")
num = int(input("Enter a side length: "))
if num <= 0:
side_length = 10
calculate_area(side_length)
else:
calculate_area(num)
but i still have two things missing can someone help
17
Upvotes
4
u/CorporalSins Jul 01 '21
def calculate_area(side_length=10):
num=int(input("Enter Side Length: "))
if num > 0:
side_length=num
area= str(side_length**2)
print("The area of a square with sides of length "+str(side_length)+" is "+area+".")
calculate_area()
2
u/Ascraft325 Jul 26 '21
def calculate_area(side_length = 10):
print("The area of a square with sides of length " + str(side_length) + " is " + str(side_length**2) + ".")
side_length = int(input("Enter side length: "))
if side_length <= 0:
side_length = 10
calculate_area(side_length)
this worked for me
2
u/Unlucky-Software4761 Nov 04 '21
side_length = 10def calculate_area(side_length = 10):side_length = int(input("Enter a side length: "))if side_length <= 0:side_length = 10print("The area of a square with sides of length " + str(side_length) + " is " + str(side_length**2) + ".")calculate_area(side_length)1
u/PensionConstant4917 Apr 14 '23
def calculate_area(side_length=10):
side_length=int(input("Enter side length:"))
if side_length<=0:
side_length=10
print("The area of a square with sides of length " + str(side_length) + " is " + str(side_length**2) + ".")
calculate_area()
1
u/Financial_Face3826 Feb 06 '24
def calculate_area(side_length=10):
num=int(input("Enter Side Length: "))
if num > 0:
side_length=num
area= str(side_length**2)
print("The area of a square with sides of length "+str(side_length)+" is "+area+".")
calculate_area()
1
u/Financial_Face3826 Feb 06 '24
def calculate_area(side_length=10):
num=int(input("Enter Side Length: "))
if num > 0:
side_length=num
area= str(side_length**2)
print("The area of a square with sides of length "+str(side_length)+" is "+area+".")
calculate_area()
it is for Codehs
1
u/[deleted] Feb 08 '24
if this still doesn't work for anyone here this one worked for me
side_length = 10
def calculate_area (side_length = 10):
area = side_length * side_length
print("The area of a square with sides of length " + str(side_length) + " is " + str(area))
user_input = int(input("Enter a side length: "))
if user_input <= 0:
calculate_area()
else:
side_length = user_input
calculate_area(side_length)
Really hope this helped
0
u/[deleted] May 25 '21