MrThoe

CodeHS 6.8

Sep 9th, 2022
952
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.71 KB | None | 0 0
  1. # This program will calculate the area of a square with side length given by
  2. # the user. If a value less than or equal to 0 is given, the default value
  3. # of 10 will be used.
  4.  
  5.  
  6. # This function calculates the area of a square and prints the output
  7. def calculate_area(side_length = 10):
  8.     area = side_length * side_length
  9.     print("The area of a square with sides of length " + str(side_length) + " is " + str(area))
  10.        
  11. # Takes the value for side length from user
  12. length = int(input("Enter side length: "))
  13.  
  14. # If the length is greater than 0, uses the value given by user.
  15. # Otherwise, uses the default value by not inputting an argument.
  16. if length > 0:
  17.     calculate_area(length)
  18. else:
  19.     calculate_area()
Advertisement
Add Comment
Please, Sign In to add comment