Conditionals & Control Flow


I'm having alot of trouble with Section 14 ( 1 got 99 problems,but a switch ain't one ) \

Here's what it comes with i copied what it started with it is not modified or been coded yet.

def greater_less_equal_5(answer):
if ________:
return 1
elif ________:
return -1
return 0

print greater_less_equal_5(4)
print greater_less_equal_5(5)
print greater_less_equal_5(6)


Ok so what is your goal here?
1.) On line 2, fill in the if statement to check if answer is greater than 5.
2.) On line 4, fill in the elif so that the function outputs -1 if answer is less than 5.
Now what does the example for this type of situation look like?

if 8 > 9:
    print "I don't get printed!"
elif 8 < 9:
    print "I get printed!"

What is the code we have been given? You have it!
How do we fill out this code with the instructions in mind like the example to solve this lesson?
Well we have our greater than 5 and we have answer. We also have the structure to our problem in

if ________:
return 1
elif ________: 
return -1

Now we just have to fill it out! Lets take the first one for example. We need to fill in the if statement to check if answer is greater than 5. That is simple enough:

if answer > 5 :

I think you can fill in the rest :smiley:


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.