## macca1111

Hi,

A simple question I think.

I want to create a function that updates variables if a certain condition is met.

For example

def main():
c=d=e=0
if c[1] == 0:
c=c+1
d=d+1
e=e+1

I want to create a function that adds the 1 to c,d,e automatically.

def BB(c,d,e)

Any help is appreciated.
macca111

## sneekula 969

Just an exercise in passing arguments to functions:

``````def increment(a, b, c):
a += 1
b += 1
c += 1
return a, b, c

def main():
c = d = e = 0
c, d, e = increment(c, d, e)
# test the result
print c, d, e  # 1 1 1
main()``````

## macca1111

Just an exercise in passing arguments to functions:

``````def increment(a, b, c):
a += 1
b += 1
c += 1
return a, b, c

def main():
c = d = e = 0
c, d, e = increment(c, d, e)
# test the result
print c, d, e  # 1 1 1
main()``````

Hi,

What if I only need to increase a or b not all of them?

macca1111

## Mouche 63

To just increase on variable such as "a" use this code in your main function:

``a += 1``

This is shorthand for a = a + 1.

## Ene Uran 638

We just discussed that in one of sneekula's threads:

``````# exercise in argument passing

def increment(*args):
"""receives tuple *args, change to list to process, then back to tuple"""
args = list(args)
index = 0
for arg in args:
args[index] += 1
index += 1
return tuple(args)

def main():
c = d = e = 0

# make sure you match arguments
c, d, e = increment(c, d, e)
print c, d, e   # 1 1 1

c, d = increment(c, d)
print c, d  # 2 2

c, = increment(c)
print c  # 3

main()``````

## macca1111

We just discussed that in one of sneekula's threads:

``````# exercise in argument passing

def increment(*args):
"""receives tuple *args, change to list to process, then back to tuple"""
args = list(args)
index = 0
for arg in args:
args[index] += 1
index += 1
return tuple(args)

def main():
c = d = e = 0

# make sure you match arguments
c, d, e = increment(c, d, e)
print c, d, e   # 1 1 1

c, d = increment(c, d)
print c, d  # 2 2

c, = increment(c)
print c  # 3

main()``````

Thks, exactly what I needed.

Maybe you could let me know why the following doesn't work.

If I do

ch =

then put in an if statement

if ch[1]==1 and ch[2:5]==0:
#add 1 to c and d

At present it doesn't recognise the second if statement and won't increase the variables.

It would have to be `if ch[1]==1 and ch[2:5]==[0,0,0]:`