Question: this code throw NameError 

```
def prime(x):

    global status

    for i in range(2, x):

        if x % i == 0:
            status = False
            break
        else:
            status = True
    return status

mylist = []

for j in range(50):

    if prime(j):
        mylist.append()

print(mylist)

```

Answer: 
* You don't need `global` (you **never** need `global`)
* Your first run of `prime` is `prime(0)` so `for i in range(2, 0)` never runs, meaning that `status` was not defined -- hence your error
* you don't append anything to `mylist`

---

```
def prime(x):
    if x < 2:
        return False  # 0, 1 are not prime
    for i in range(2, x):
        if x % i == 0:
            return False
    return True

mylist = []

for j in range(50):
    if prime(j):
        mylist.append(j)

print(mylist)

```
The problem is that `status` *is not guaranteed* to have a value. If you pass `x=0`, your loop doesn't run, and then you `return status`. What would its value be? If eg, you change your loop to `range(2, 10)` its runs fine (it doesn't make sense in your case, just trying to show the problem).

However, since you just `append` the returned value to a list, don't use a global. Just return the value.