Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # This program will calculate the area of a square with side length given by
- # the user. If a value less than or equal to 0 is given, the default value
- # of 10 will be used.
- # This function calculates the area of a square and prints the output
- 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))
- # Takes the value for side length from user
- length = int(input("Enter side length: "))
- # If the length is greater than 0, uses the value given by user.
- # Otherwise, uses the default value by not inputting an argument.
- if length > 0:
- calculate_area(length)
- else:
- calculate_area()
Advertisement
Add Comment
Please, Sign In to add comment