Question: I would like to find out how you can tell if a character in a variable is a letter or number

for example:
if I used the code: ABC123

How would I find out if a variable followed that pattern so if a inputted code would be DNM567 it would print "correct"
But if a code was DNM56T it would print "incorrect". 

Many thanks

Answer: 
The ***wrong*** way to do this:

```
val1 = 0

...

def lame(x):
    global val1
    val1 = result_of_some_calculations_to_do_with(x)

```

The ***right*** way to do this:

```
def lame(x):
    return result_of_some_calculations_to_do_with(x)

val1 = lame(x)

```

Contrary to what L3viathan said in the comments, Python DOES pass variables by reference, but does not ASSIGN variables by reference. In other words:

```
x = 3 # x is 3
y = x # x is 3, y is 3, x is y
y = 4 # x is 3, y is 4, y is REASSIGNED so y is not x

```

That's basically what you were trying to do, passing `val1` to your `lame` function and rebinding it as `y`.

```
val1 = 0 # val1 is 0

def lame(x, y):
    # y is val1
    y = some_calculations_to_do_with(x)
    # y has been REASSIGNED so y is not val1

```

This is important when you pass objects like lists that are mutable (e.g. they can be changed, as opposed to immutable objects line `int` and `str` in Python).

```
val1 = list() # val1 is an empty list

def lame(x,y):
    y.append(x) # append x to y, DO NOT REASSIGN y TO ANYTHING ELSE

lame(1, val1) # val1 is [1]

```
Right after I posted this question I figured it out, and can confirm what Adam Smith has said.

Here is the code I changed to get it working properly:

```
def lame(x): 
    #set value of p, r, s choice to 1, 2 or 3 
    if x in("p","P"):
        return 1
    elif x in("r","R"):
        return 2
    elif x in("s","S"):
        return 3
    else:
        print("your value was not p, r or s")

#run function "lame" and pass in play1 choice and 
#retrive val1 for that choice
val1 = lame(play1)
val2 = lame(play2)

```