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 exercises_user_defined_functions.md #6

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions planning/exercises_user_defined_functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,30 @@
Try to reuse the first maximum of two numbers function.
3. Write a Python function that accepts a list as a parameter. Next, it
determines and prints the number of positive and negative numbers.

def max_of_two(x,y):
"""Returns the maximum of two variables x and y."""
if x>y:
return x
else:
return y

def max_of_three(x,y,z):
"""Returns the maximum of two variables x and y."""
if x>y and x>z:
return x
elif z>x and z>y:
return z
else:
return y

def pos_or_neg(aList):
"""Returns the positive and negative values of a list."""
positive=[]
negative=[]
for i in aList:
if i>=0:
positive.append(i)
else:
negative.append(i)
return print("The positive values in the list are: ",positive,". The negative values in the list are: ",negative,".")