Lesson 14 - I have 99 problems, but a switch is not a


#1

I'm not understanding this lesson. Help me please.
Ps: Sorry for my spelling mistakes.

def greater_less_equal_5(answer):
    if 2 * 3:
        return 1
    elif 4 - 5:          
        return -1
    else:
        return 0
        
print greater_less_equal_5(4)
print greater_less_equal_5(5)
print greater_less_equal_5(6)

#2

look at this code plus comments:

# function with parameter answer
def greater_less_equal_5(answer):
     print answer

# function calls with different arguments
print greater_less_equal_5(4)
print greater_less_equal_5(5)
print greater_less_equal_5(6)

see how the arguments supplied at function call get copied into function parameter? So if we then compare the function parameter (answer) with 5, our function can determine if the value we supply is greater, equal or smaller then 5


#3

Excuse me. I still do not understand.


#4

well, answer contains a value (depending on the value passed as argument in function call), so if we use answer in our comparisons, we can make a function return 1, 0 or -1 depending on if answer is greater, equal or smaller then 5


#5

I still do not understand, but I'll try again.


#6

if you where in my shoes, how would you respond to i don't understand? Unless you explain me what you do/don't understand (with code samples), i can't help you further.

Read my answers again, read the instructions again, try if you see a connecting. Think about what the function is suppose to do, how parameters and arguments play a roll in this


#7

Is that your writing to me is not clear enough. It's still a little technical.

Edit:I went out for lunch. I'll be back later.


#8

programming is technical, how do you explain something technical in a non-technical way? Its fine when someone you talk to at a party asks you about your IT profession, then its fine to give a non-technical explanation. But you actually need to get pass the exercise, how should i do this with a non-technical explanation?


#9

I know that programming language is technical but gives yes to give a non-technical explanation.
But thanks for the support.
I'll keep trying to work out the exercise.


#10

If you need more help, post an updated version of your code + question + error message


#11

A post was split to a new topic: I have 99 problems, but switch aint one


#12

I'm still I'm going to try something new and already put here to see if it worked.

Edit: I was able to do the if function but I'm still not understanding what it is to do in the elif function

def greater_less_equal_5(answer):
    if 6 > 5:
        return 1
    elif:          
        return -1
    else:
        return 0
        
print greater_less_equal_5(4)
print greater_less_equal_5(5)
print greater_less_equal_5(6)

The following error is returning:
Oops, try again. If the result of your function was 1 instead of -1 when answer is 3. Make sure you have filled in the if and elif statements correctly!

Edit:I was able to solve it (not alone).


#13

I'm also stuck on this question as well please help


#14

so these function calls:

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

the function needs to determine if these numbers (4,5 and 6) are greater or equal to 5. So, in our function, for our if condition and elif condition, we need to compare if answer (the function parameter) is greater then 5, else if smaller then 5 or else equal to 5


#15

I think the challenge here is understanding the action/function of the word "answer" and how to write the syntax that allows the function "greater" to calculate that the "answer" is in fact "greater" than 5.

I've tried several mathematical equations and can't get the "equal to" to work. I've tried "answer ==5" . I've tried "answer 10-5." For greater than I configured "answer > 5" I don't know if that's correct because my instance is only throwing an error at line 6 "else answer equals 5."

What I know about programming would fit into a thimble and all I've learned is from this fantastic learning program in the past 2 hours. SO - There are some functions in this module that are new and have not been covered in this syntax. What is the syntax to compare "print greater...(4)" to the number 5?

you mean like this:

if answer > 5 :

elif answer < 5 :

else :

if that's what you are saying - that's what I was using BUT the output from that gives me this:

-1
1
0

Shouldn't the order of those be:

1
-1
0

r/
Tammy


#16

but for answer equals 5, no condition has to be set? Else will run, given all other scenarios (lesser and greater then 5) have already be covered.

This is what you get from the lesson:

def greater_less_equal_5(answer):
    if ________:
        return 1
    elif ________:          
        return -1
    else:
        return 0
        
print greater_less_equal_5(4)
print greater_less_equal_5(5)
print greater_less_equal_5(6)

you only need to set if and elif condition


#17

@tammy9931 , do you speak Brazilian Portuguese?
My English writing is not very good.


#18

you mean like this:

if answer > 5 :

elif answer < 5 :

else :

if that's what you are saying - that's what I was using BUT the output from that gives me this:

-1
1
0

Shouldn't the order of those be:

1
-1
0

r/
Tammy


#19

Guys, I sinned a lot trying to understand the lesson. I received the answer by asking in another forum because you really can not understand the instruction of the lesson.

I will try to explain in my own way what you have to do in this lesson.
Both statements ask you to use the answer statement to construct the function, that is, the answer statement will be one of the values / algorithms of this function.

If you do not understand, answer here and I'll send you the answer through the message.


#20

Then I'm not configuring the syntax correctly based on the output from my lab:

"if answer > 5" with "elif answer < 5."

If " answer > 5" returns a "1"
Elif " answer < 5" returns a "-1"
Else blank returns a "-1" and an Error
"Opps, it looks like your function output 1 instead of -1 when answer is 3. Make sure you filled in "if" and "elif" correctly.

you mean like this:

if answer > 5 :

elif answer < 5 :

else :

if that's what you are saying - that's what I was using BUT the output from that gives me this:

-1
1
0

Shouldn't the order of those be:

1
-1
0

Thanks for your time,

r/
Tammy