White loops question


#1

I have a simple question.

So if I am creating a while loop function and the function requires an 2 inputs (see below):

def my_simple_while_function(low,max):
    low = 0
    while low < max:
        print "We need more numbers becase low is only %d and we need it to equal %d in order to break this while loop" % (low, max)
        low = low + 1

Now if I call this function with say: my_simple_while_function(4,10) - 4 get’s set to zero because I set low = 0 - but thats because its the only way I know how to start storing to low vs. using the raw input (4).

How I can build function that takes lows input when I call the function without overriding it, but still able to add to it?


#2

you can the pass the value for low as argument on function call, currently you overwrite the function parameter, which is a bad idea


#3

parameters are regular variables


#4

ok so I can manipulate low without using low = 0?


#5

you can manipulate the value of the parameter within the function, this is a possibility. But currently you just overwrite the parameter/variable, which is a bad idea.


#6

ok so I would change it to low = low if I wanted it to start with the original input when I call the function?


#7

why would you do that?

I recommend you to do some research on function, function parameters, function calls and function arguments


#8

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