Python Forum
Rock, Paper, Scissors.. Help..hidden bug
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Rock, Paper, Scissors.. Help..hidden bug
#1
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))
Reply
#2
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.
Reply
#3
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
Reply
#4
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
Reply
#5
The format looks good, though you could eliminate counter and just compare to the sum of player_score and computer_score
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Rock Paper Scissors Project in Python ankitdixit 8 4,816 Feb-23-2024, 03:14 PM
Last Post: DPaul
  Copy only hidden files and folders with rsync Cannondale 2 997 Mar-04-2023, 02:48 PM
Last Post: Cannondale
  Trying to create a visual rock paper scissors game urmom33 1 1,027 Dec-03-2022, 09:12 PM
Last Post: deanhystad
  Can ZipFile be used to extract hidden files? AiedailEclipsed 0 1,615 Mar-22-2022, 05:21 PM
Last Post: AiedailEclipsed
  Rock paper scissors in python with "algorithm" Agat0 23 5,995 Mar-01-2022, 03:20 PM
Last Post: Agat0
  Problem restricting user input in my rock paper scissors game ashergreen 6 4,590 Mar-25-2021, 03:54 AM
Last Post: deanhystad
  Odd behavior with Rock Paper Scissor game DustinKlent 2 1,932 Aug-27-2020, 03:55 PM
Last Post: DustinKlent
  Run hidden exe samuelbachorik 0 2,702 Aug-02-2020, 03:10 PM
Last Post: samuelbachorik
  Trying to implement Best of 3 logic in rock paper scissors game ShAhCh 5 3,348 May-11-2020, 04:31 PM
Last Post: ShAhCh
  Rock Paper Scissors with dictionaries ewgreht 2 3,886 May-01-2020, 03:19 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020