Ask coding questions

← Back to all posts
Why does it keep printing 'None'?
BananaJellyfish (206)

go to the bathroom using '1'. it should be printing a random weapon(line 181) but instead it prints 'None'. i just can't figure out the problem

Answered by IMayBeMe (346) [earned 5 cycles]
View Answer
Comments
hotnewtop
IMayBeMe (346)

The issue is that you never actually return a weapon so it can be fixed by doing the following:

def gen_wep(wep):
  n = randint(1,100)
  if n < 6:
    wep = ['Rocket launcher']
    weapons.append(wep)
  if n > 5  < 30:
    wep = random.choice(['Shotgun','Machine Gun'])
    weapons.append(wep)
  if n > 29:
    wep = random.choice(['AK-47','Pistol'])
    weapons.append(wep)
  return wep

It should work

IMayBeMe (346)

Also, get rid of:

gen_wep(wep)
print(purple+'You found a '+green+str(wep)+white)

On line 201 and 202 and replace it with:

print(purple+'You found a '+green+gen(wep)+white)
LukeWright (114)

I dont see a print statement on line 181. can you be more specific?

BananaJellyfish (206)

@LukeWright yes, gen_wep() is on line 181. then, on line 199, there is an if statement that calls gen_wep() and prints wep

LukeWright (114)

why did you do

from random import randint

I think the problem is that you imported randint instead of just importing random. IDK tho.
@BananaJellyfish

LukeWright (114)

try importing random and changing all occurences of

randint

to

random.randint

@LukeWright

BananaJellyfish (206)

@LukeWright thats for when i wanted to make chance randint(1,10). it isnt causing the bug