Skip to content
Sign upLog in
← Back to Community

Why does it not work properly?

Profile icon
CapnDom

So I am fairly new to coding in general, this is but my second repl, but I am stumped. I look at it for such a long time now I just feel stuck.

Whenever I play I lose.

I am really not sure why, I set parameters, I have written out all possible actions and yet I never can win or tie.

Can you have a look over this and tell me where it went wrong?

BTW: I used to initially code with elif instead of if statements below, but it didn't change much. The lose messages were modified so I can see where the error occurs.
The programm recognises my input and then simply skips the win or tie scenarios and immediately prints the lose messages, the "else" parameters.

Voters
Profile icon
CapnDom
Comments
hotnewtop
Profile icon
MikeW3

computer_choice is the LIST of choices, but you expect it to be the choice chosen

The actual choice the computer picked is lost due to it being only in the print statement and not saved as a variable

Profile icon
CapnDom

@MikeW3
Yeah, I just saw that I didn't change it back. As I commented I had this rewritten and just for the sake of it put back in.

Initially it was JUST line 14, but I was playing around, hoping to find the problem that way.

If you take my code, erase line 15, 16 and 17 it still doesn't work.

Profile icon
MikeW3

@CapnDom

this should fix

Computer = random.choice(computer_choice) print("You chose "+game, "and I chose "+Computer) #random choice works fine, does what it should if Computer == game: print("Okay, looks like we tied here. Let's play another game.") if game == "rock": if Computer == "scissors": print ("You win, "+name) else: print("You lost.rock") if game == "paper": if Computer == "rock": print("Good Job, you win "+name) else: print("You lost, sorry.paper") if game == "scissors": if Computer == "paper": print ("You won! Congratz, "+name) else: print("Sorry, you lost.scissors") retry = input ("Retry? Yes/No\n") if retry == "no": break
Profile icon
CapnDom

@MikeW3
Yes, yes. I was a little quick. I changed it myself before I saw your comment, but now it works perfectly fine. Thank you for your help.

I now need to sit down and try to understand why it didn't work before.

Profile icon
MikeW3

@CapnDom
the reason it did not work before is what I said
computer_choice is the LIST of choices, but you expect it to be the choice chosen

The actual choice the computer picked is lost due to it being only in the print statement and not saved as a variable

Profile icon
CapnDom

@MikeW3
Ohh.. I think I got it now. Thanks. I am going to add a few more things and see where I go.

This community is great. :)

Profile icon
MikeW3

@CapnDom
if this answer solved it, please mark this as the correct answer