Python Forum
A CLI based Rock,Paper or Scissor game.
Poll: Did you like my program?
You do not have permission to vote in this poll.
Yassss
33.33%
1 33.33%
No.
66.67%
2 66.67%
Total 3 vote(s) 100%
* You voted for this item. [Show Results]

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
A CLI based Rock,Paper or Scissor game.
#1
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
Reply
#2
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.
Reply
#3
(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.
Reply
#4
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.
Reply
#5
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).
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#6
Is there an option to delete my forum account?
Reply
#7
We don't delete accounts on this site.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#8
(Oct-27-2018, 08:56 PM)ichabod801 Wrote: We don't delete accounts on this site.
Awesome.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Another Rock, Paper, Scissors Yoriz 4 3,150 Jun-30-2020, 07:56 PM
Last Post: Yoriz
  The tkinter version of Rock Paper Scissors menator01 3 3,159 Jun-28-2020, 07:15 AM
Last Post: ndc85430
  My version of Rock Paper Scissors menator01 12 6,061 Jun-27-2020, 10:25 PM
Last Post: menator01
  PyQt5 Version of Rock, Paper, & Scissors menator01 8 3,638 Jun-06-2020, 12:15 PM
Last Post: pyzyx3qwerty
  Rock, Paper, Scissors foksikrasa 11 4,289 May-28-2020, 05:58 PM
Last Post: BitPythoner
  Rock Paper Scissor GAME inamullah9 3 3,246 Aug-11-2019, 12:17 PM
Last Post: ichabod801
  A basic Rock-paper-scissors game by me... Unlimiter 0 2,470 Dec-25-2017, 03:41 PM
Last Post: Unlimiter
  Basic Rock, Paper, Scissors CinnamonBeard 1 3,537 Dec-19-2017, 02:32 PM
Last Post: sparkz_alot

Forum Jump:

User Panel Messages

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