Python Forum

Full Version: Rock, Paper, Scissors.. Help..hidden bug
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
everything running great but there is a bug that i cant find... there is not error coming back from this so basically i cant trace it back
--some times when input Scissors it return "Enter a Rock, Paper or Scissors not numbers please what the "
[Image: IZHil4E.jpg] i put the screenshot if not working here is the link https://pasteboard.co/IZHil4E.jpg

import random

options = ["Rock", "Paper", "Scissors"]
player = input("Whats your name: ")
counter = 0
player_score = 0
computer_score = 0
while counter < 7:

    y = str(input("Rock, Paper or Scissors: "))
    x = random.choice(options)
    counter += 1

    if x == y:
        print("Draw again....... ")
        counter -= 1
        # rock wins  ....................... paper wins
    elif y == "Rock" and x == "Paper":
        player_score += 1
        print("Fuck that your good! you win this time! ")
        print(x)

    elif y == "Scissors" and x == "Paper":
        player_score += 1
        print("That's some bullshoot dude again!!! ")
        print(x)

    elif y == "Paper" and x == "Rock":
        player_score += 1
        print("im outta here your FEAKNIN CHEATING!!!  ")
        print(x)

    elif x == "Rock" and y == "Paper":
        computer_score += 1
        print("I beat yo ass you stupid your not going to make it!!!  ")
        print(x)

    elif x == "Scissors" or y == "Paper":
        computer_score += 1
        print("that how you do it !!! ")
        print(x)

    elif x == "Paper" and y == "Rock":
        computer_score += 1
        print("I will be wining a ")
        print(x)

    elif y != str:
        counter += 0
        print("Enter a Rock, Paper or Scissors not numbers whats wrong with you!!")


if computer_score > player_score:
    print("{} i win you doofus!! my score is {} and yours {}".format(player, computer_score, player_score))
else:
    print("{} you win this your score is {} and mine is {} ".format(player, player_score, computer_score))
On line 48, you're checking whether y is equal to the function str. Clearly, that will never be True. You don't want to check whether y is of type str, either (with isinstance) because on line 10, you know it's already a string. Incidentally, you don't need the call to str on line 10, since input already returns a string. If you want to check whether a string contains only alphabetical characters, then have a look at the documentation to see if you can find an appropriate method.

Also, variable names like x and y are pretty meaningless - use names that tell you what the variable is for. That helps everyone (you included) to read and therefore understand the code.
Line 48 is your error. A few ways to fix, look at this code:
print(str)
print(str == 'string')
print(type('string'))
print(str == type('string'))
Output:
<class 'str'> False <class 'str'> True
I think you are trying to see if y is a string. You can check the type, or you could try isinstance() to see if y is in the str class
I've changed line 48 with this
elif y not in options:
        print("Enter any of the options ")
that works great so far actually. what do you think about my counter i wanted to make a counter of 5 if the computer or player gets 5 points first it prints out one of the last print statements at line 53

(Mar-18-2020, 06:43 PM)ndc85430 Wrote: [ -> ]On line 48, you're checking whether y is equal to the function str. Clearly, that will never be True. You don't want to check whether y is of type str, either (with isinstance) because on line 10, you know it's already a string. Incidentally, you don't need the call to str on line 10, since input already returns a string. If you want to check whether a string contains only alphabetical characters, then have a look at the documentation to see if you can find an appropriate method.

Also, variable names like x and y are pretty meaningless - use names that tell you what the variable is for. That helps everyone (you included) to read and therefore understand the code.

I've changed line 48 with this

elif y not in options:
        print("Enter any of the options ")
that works great so far actually. what do you think about my counter i wanted to make a counter of 5 if the computer or player gets 5 points first it prints out one of the last print statements at line 53
The format looks good, though you could eliminate counter and just compare to the sum of player_score and computer_score