Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update 10_functions_exercise.py #231

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 8 additions & 9 deletions Basics/Exercise/10_functions/10_functions_exercise.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,15 @@ def calculate_area(dimension1,dimension2,shape="triangle"):
:param dimension2: In case of triangle it is "height". For rectangle it is "width".
:param shape: Either "triangle" or "rectangle"
:return: Area of a shape
'''
if shape=="triangle":
area=1/2*(dimension1*dimension2) # Triangle area is : 1/2(Base*Height)
elif shape=="rectangle":
area=dimension1*dimension2 # Rectangle area is: Length*Width
def Calculation_area(dimension1,dimension2, a = 'area' ):
if a == 'area':
area = (1/2)*dimension1*dimension2
print(area)
else:
print("Error: Input shape is neither triangle nor rectangle.")
area=None # If user didn't supply "triangle" or "rectangle" as shape then return None
return area
rectangle_area = dimension1*dimension2
print(rectangle_area)

Calculation_area(15,10,'triangle')

# 1. Write a function called calculate_area that takes base and height as an input and returns and area of a triangle. Equation of an area of a triangle is,
# ```
Expand Down Expand Up @@ -87,4 +86,4 @@ def calculate_area(dimension1,dimension2,shape="triangle"):
print("Print pattern with input=4")
print_pattern(4)
print("Print pattern with no input number")
print_pattern() # Not supplying any input will use default argument which is 5
print_pattern() # Not supplying any input will use default argument which is 5