I Got 99 Problems, But a Switch Ain't One


#1


#2

I can see that the instructions state to use the variable answer, which is in your function parameter greater_less_equal_5(answer), for your if and elif statements. Not random numbers.

answer is a placeholder variable that when you call a function, you can replace it with a number such as 4 in your print statement. And so the function will switch answer with 4 and evaluate that.


#3

I entered my suggestion now the wheel keeps turning like I am stuck in some sort of infinite do-loop or something
I tried again and hit clear code now it offers UnDo but when I choose that, the cogwheel keeps turning,,,What Up?
How do I get a fresh start?


#4

I'd just close the tab and reopen a new one.
Or sometimes, I just close the browser all together.


#5

def greater_less_equal_5(answer):
if answer > 5:
return 1
elif answer < 5:
return -1
else:
return 0

This is the right answer, but i actually haven't really understood what's going on. If somebody can explain in greater detail would be appreciated


#6

def greater_less_equal_5(answer): #define the function
    if answer > 5: #checking to see if the answer input is greater than 5
        return 1 #if it is, return 1
    elif answer < 5: #checking to see if the answer input is less than 5
        return -1 #if it is, return -1
    else: #otherwise
        return 0 #return 0

You can see if it works by calling the function and replacing answer with a random number in a print statement like this:

def greater_less_equal_5(answer): #defined the function
    if answer > 5: #checking to see if the answer input is greater than 5
        return 1 #if it is, return 1
    elif answer < 5: #checking to see if the answer input is less than 5
        return -1 #if it is, return -1
    else: #otherwise
        return 0 #return 0

print greater_less_equal_5(4) #call function and replace answer with 4 in print statement

And you'll see a -1 in your console/output because 4 is less than 5.


#7

Thanks very much, it makes it more clear, but...i think i'm missing the general purpose of the exercise here:

1) What is that we are trying to define or obtain?
2) From where this input you are talking about should came from? i'm mean...'answer' to what?

...sorry, i'm very newbe to code


#8

The instructions should tell you what you are supposed to do. They want you to define a function called greater_less_equal_5 for the user to use. The purpose of this is that if the user were to type a random number, the function would output something.

The input came from your declaration of the function

def greater_less_equal_5(answer): #in the brackets

This is the syntax for starting a function. answer is an input variable (aka parameter) such as in math, you have a function f(x) = x + 5 that x in the bracket is your input. Whatever you put as x, let's say 1, your f(x) outputs 6. Same concept for the variable, answer.


#9

ur a real savage, thank you ^_^


#10

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