Python Forum
A CLI based Rock,Paper or Scissor game. - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: General (https://python-forum.io/forum-1.html)
+--- Forum: Code sharing (https://python-forum.io/forum-5.html)
+--- Thread: A CLI based Rock,Paper or Scissor game. (/thread-13675.html)



A CLI based Rock,Paper or Scissor game. - Ablazesphere - Oct-26-2018

Please like my post if you did. Dance Dance

import time
import random

j = 0

choice = 'y' or 'n'
point_pc = 0
point_user = 0

user = input("Enter your name : ")

while choice.lower() in ('y'):
    j = 0
    x = ["Rock","Paper","Scissor"]
    pc = x[random.randint(0,2)]    
    print()
    player = input("Rock Paper or Scissor? : ")
    print()
    if player == pc:
        print("Its a Tie!!!")
        point_pc += 0
        point_user += 0
    elif player == "Rock" or player == "rock":
        if pc == "Paper":
            print()
            print("You Lose")
            point_pc += 1
            point_user += 0
        else:
            print()
            print("You Win")
            point_pc += 0
            point_user += 1
    elif player == "Paper" or player == "paper":
        if pc == "Scissor":
            print()
            print("You Lose")
            point_user += 0
            point_pc += 1
        else:
            print()
            print("You Win")
            point_user += 1
            point_pc += 0
    elif player == "Scissor" or player == "scissor":
        if pc == "Rock":
            print()
            print("You Lose")
            point_user += 0
            point_pc += 1
        else:
            print()
            print("You Win")
            point_user += 1
            point_pc += 0
    while player.lower() not in ('rock','paper','scissor'):
        print()
        print("There must be some splelling Mistake that caused the Error. Try again.")
        print()
        break
    print()
    choice = input("Would you like to play again? : ")

while choice.lower() in ('n'):
    print()
    k = print("Points scored by the pc is =",point_pc)
    z = print("Points scored by the user is =",point_user)
    print()
    if point_pc > point_user:
    	print()
    	print()
    	print("PC WINS THE MATCH.")
    else:
    	print()
    	print()
    	print(user,"WINS THE MATCH")
    print()
    print()
    print()
    print()
    print()
    print()
    print()
    print()
    print("Coded by Muhammed©")
    break
time.sleep(10)

Good comments and compliments will be appreciated and keep your mean comments to yourself. Cool


RE: A CLI based Rock,Paper or Scissor game. - micseydel - Oct-26-2018

I only vaguely looked at your other thread, so forgive me if this is "mean" instead of a "good comment" but:
Line 6 evaluates to 'y', which is probably not what you intended.
Line 12 behaves as it appears you intended, but not for the reasons it looks like. If you change 'y' to 'yes' and play with it you might see why. (Line 64 has the same problem.)
On line 15 you can use random.choice() and skip using an index (I would consider that more elegant, since it skips the implementation detail of the index).
Lines 21 and 22 can be omitted. The other +=0 lines later can be as well.
Line 23 could be even more robust by using player.lower() == "rock".
Lines 25 and 30 can be consolidated into a single on between lines 23 and 24.
Your loop on line 56 could/should just be an if, since you break unconditionally within it. Same with the loop on line 64.
You have logic that looks like the game will restart if a player chooses to do so, but it doesn't actually.


RE: A CLI based Rock,Paper or Scissor game. - Ablazesphere - Oct-26-2018

(Oct-26-2018, 04:47 PM)micseydel Wrote: I only vaguely looked at your other thread, so forgive me if this is "mean" instead of a "good comment" but: Line 6 evaluates to 'y', which is probably not what you intended. Line 12 behaves as it appears you intended, but not for the reasons it looks like. If you change 'y' to 'yes' and play with it you might see why. (Line 64 has the same problem.) On line 15 you can use random.choice() and skip using an index (I would consider that more elegant, since it skips the implementation detail of the index). Lines 21 and 22 can be omitted. The other +=0 lines later can be as well. Line 23 could be even more robust by using player.lower() == "rock". Lines 25 and 30 can be consolidated into a single on between lines 23 and 24. Your loop on line 56 could/should just be an if, since you break unconditionally within it. Same with the loop on line 64. You have logic that looks like the game will restart if a player chooses to do so, but it doesn't actually.

Wait. It should have restarted let me check bro.

(Oct-26-2018, 04:47 PM)micseydel Wrote: I only vaguely looked at your other thread, so forgive me if this is "mean" instead of a "good comment" but: Line 6 evaluates to 'y', which is probably not what you intended. Line 12 behaves as it appears you intended, but not for the reasons it looks like. If you change 'y' to 'yes' and play with it you might see why. (Line 64 has the same problem.) On line 15 you can use random.choice() and skip using an index (I would consider that more elegant, since it skips the implementation detail of the index). Lines 21 and 22 can be omitted. The other +=0 lines later can be as well. Line 23 could be even more robust by using player.lower() == "rock". Lines 25 and 30 can be consolidated into a single on between lines 23 and 24. Your loop on line 56 could/should just be an if, since you break unconditionally within it. Same with the loop on line 64. You have logic that looks like the game will restart if a player chooses to do so, but it doesn't actually.

Dude i checked and it restarts as it should have and yes you wont get it right if you input 'yes' instead of 'y' cause this isn't a perfectly built program. Thank You for letting me know the minor things which i could later on update it. This is the kind of comments which i expect the last one ended up saying "Do whatever you want" this pissed me off.
Anyway Thank You.


RE: A CLI based Rock,Paper or Scissor game. - micseydel - Oct-26-2018

My apologies, I wasn't reading carefully and the code is hard to follow.

The last part at the end, that says the score only happens if the user says "n" (rather than anything except "y"). I was thrown off by the loop which can only ever happen once and seems like it should be unconditional.


RE: A CLI based Rock,Paper or Scissor game. - ichabod801 - Oct-26-2018

The line while choice.lower() in ('n'): should be if choice.lower() == 'n':. The loop only runs once, so it should be an if statement. You do that a lot, but it's just going to confuse people trying to read your code, just as it confused micseydel. And if you have only one option, there's no need to use the in operator.

Rock, paper, scissors is a perfect example of how using a dictionary rather than a bunch of if/elif/else statements can make things much easier. With the dictionary wins = {'rock': 'scissors', 'scissors': 'paper', 'paper': 'rock'} you can easily check for valid answers (player.lower() in wins), and wins ( if wins[player.lower()] == pc).


RE: A CLI based Rock,Paper or Scissor game. - Ablazesphere - Oct-27-2018

Is there an option to delete my forum account?


RE: A CLI based Rock,Paper or Scissor game. - ichabod801 - Oct-27-2018

We don't delete accounts on this site.


RE: A CLI based Rock,Paper or Scissor game. - Ablazesphere - Oct-28-2018

(Oct-27-2018, 08:56 PM)ichabod801 Wrote: We don't delete accounts on this site.
Awesome.