Hey there, so I recently joined an online course, and the first mini-project is to create rock, paper, scissors, lizard, spock.

upon testing my program it seems I've got an error in my code and I can't for the life of me figure it out, I was hoping you guys could help me fix it.

I get this error unsupported operand type(s) for Sub: 'number' and 'NoneType'
for this line victor = (c_num - p_num) % 5

The issue seems to be with p_num, but I can't figure it out, if it helps, here is all the stuff to do with p_num

p_num = name_to_number(guess)

def name_to_number(guess):

if guess == "rock":
    p_num = 0

elif guess == "spock":
    p_num = 1

elif guess == "paper":
    p_num = 2

elif guess == "lizard":
    p_num = 3

elif guess == "scissors":
    p_num = 4`

Edited 4 Years Ago by barrelr0ll

Add return p_num at the end of the function. Your function currently returns None. The p_num inside the function is not the same as the p_num outside the function (because it appears in the left part of assignment statements). It is a local variable. You need a return statement to catch its value.

Edited 4 Years Ago by Gribouillis

Thanks Grib, though that didn't seem to change anything :(
I guess I'll try to wrack my braina bit more, I don't want to bother you guys with the entire 60ish lines of code, I've noticed people here get annoyed at that lol

Well, it's not so much that (especially since 60 lines isn't all that much) as it is the tendency of newcomers to simply post their code without actually asking a question about it.

In this case, we'd also need to see where you are setting c_num, as well.

Edited 4 Years Ago by Schol-R-LEA

Thank you so much for showing interest in helping me, but I just managed to fix it myself, I'm not entirel sure how, but I just took apart the code, reconstructed in in a new file while making slight improvements to the code.

Once again, thanks anyway!

This question has already been answered. Start a new discussion instead.