r/pythonhelp • u/liquidheaven • Jul 13 '23
Beginner - How to increment a 2 player rock, scissors, paper game until one person wins 3 games
I am not sure what I am doing wrong here but it stays on 'Round 1' no matter how many rounds you play.
print("Let's play ROCK PAPER SCISSORS! ")p1score = 0 p2score = 0 p1 = input("Player 1 name: ") p2 = input("Player 2 name: ") counter = 1 while True: r=("R","ROCK", "rock", "Rock", "r") s=("S", "s", "Scissor", "scissor", "SCISSOR") p=("P", "p", "Paper", "paper", "PAPER") print() print() print ("Select your moves!") p1move = input("Player1 move>") p2move = input("Player2 move>") print("Round...", counter,+1)
if p1move in r and p2move in r: print(p1, p2,"Rocks and Rocks... it's a tie!")
elif p1move in r and p2move in p: print(p2, "Wins by wrapping the rock in the paper!" ) p2score += 1
elif p1move in r and p2move in s: print(p1,"Wins by breaking the scissors!! 🥳") p1score += 1
elif p1move in p and p2move in r : print(p1,"Wins by wrapping Rocks with paper 🥳") p1score += 1
elif p1move in p and p2move in p : print("Its a Draw 🥺")
elif p1move in p and p2move in s : print(p2,"Win 🥳") p2score += 1
elif p1move in s and p2move in r : print(p2,"Wins 🥳") p2score += 1
elif p1move in s and p2move in p : print(p1,"Wins 🥳") p1score += 1 else: if p1move in s and p2move in s : print("Its a draw again 🥺 ")
if p1score == 3 or p2score == 3 : print (p1,"has",p1score,"and",p2,"has",p2score)
breakelse:
continue1
u/liquidheaven Jul 13 '23
I also do not know how to submit a code block appropriately. Any help please?
1
u/CraigAT Jul 13 '23
There's a guide linked to in the "community info" of the sub and in a "sticky post" at the top of the sub.
https://commonmark.org/help/tutorial/09-code.html
Some people will indent the code extra in your IDE/editor and then paste here, I tend to find it easier to copy my code to Pastebin and add a link in the post here.
Hope this helps.
2
1
u/CraigAT Jul 13 '23 edited Jul 13 '23
You never increment the counter, you only print it. You may be trying to increment it in the print statement but that won't work as you hope.
Personally, I would set counter to 0 before the loop, and then first thing inside the loop increment the counter (the alternative would be to set it to 1 before the loop and then increment at the end of the loop)
2
u/liquidheaven Jul 13 '23
I didn’t realize you have to set it outside then call it inside the loop. Thank you
1
u/CraigAT Jul 13 '23
You don't have to set it outside, but if you set inside the count will reset every time it comes back around the loop (which is not usually the desired behaviour)
1
u/liquidheaven Jul 13 '23
This works but I am wondering if I have extraneous code?
Also, how would I save the p1 & p2 inputs (player name 1 & 2), print them and ask for the player's move? Can I do that in one line of code? i.e. "CraigAT, rock, paper or scissors?"
Thanks for your help
1
u/CraigAT Jul 14 '23
To print the player name and get the input using the line I would create the line you want as a string and pass that to the input line. Not sure if you can add the variable within the input (I'd need to test, f-strings may help too).
You could definitely reduce the code, but this is not code golf, for now concentrate on making it understandable. One way you could cut down on your code is by considering just the outcomes: P1 wins, P2 wins or the draw.
1
u/liquidheaven Jul 14 '23
Did you find out if you can add the variable within the input? It would be much sleeker.
I am not to f-strings yet, just starting my Python education.
Thanks again for the help!
1
u/CraigAT Jul 15 '23
It looks like: https://stackoverflow.com/a/42104601
If you are teaching yourself and using a modern version of Python, I would learn f-strings, they are very useful for outpouring and basic debugging. If you are course-led then ask if they will cover them and wait.
2
u/liquidheaven Jul 15 '23
Self learning using premade Replit courses. The % method looks pretty simple. I am sure we’ll get there. Thank you
•
u/AutoModerator Jul 13 '23
Note:
This sub went private for a few days recently in solidarity with other subs who are hoping to get Reddit to reconsider some changes that they have proposed. These changes will affect the Reddit API and many third-party apps that access Reddit. If you are not already aware of the proposed changes, please read up on the topic and the ongoing protest.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.