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`

Recommended Answers

All 4 Replies

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.

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.

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!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.