Python Forum
Rock Paper Scissors Project in Python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Rock Paper Scissors Project in Python
#1
Hello All,I am working on some python projects and i want to confirm that the given sample code is correct or not? Basica;;y the objective is a random function: to generate rock, paper, or scissors. valid function: to check the validity of the move. result function: to declare the winner of the round. scorekeeper: to keep track of the score. Or can anyone suggest me some new python projects as a beginner level?
""" Rock Paper Scissors
----------------------------------------
"""
import random
import os
import re
os.system('cls' if os.name=='nt' else 'clear')
while (1 < 2):
    print "\n"
    print "Rock, Paper, Scissors - Shoot!"
    userChoice = raw_input("Choose your weapon [R]ock], [P]aper, or [S]cissors: ")
    if not re.match("[SsRrPp]", userChoice):
        print "Please choose a letter:"
        print "[R]ock, [S]cissors or [P]aper."
        continue
    // Echo the user's choice
    print "You chose: " + userChoice
    choices = ['R', 'P', 'S']
    opponenetChoice = random.choice(choices)
    print "I chose: " + opponenetChoice
    if opponenetChoice == str.upper(userChoice):
        print "Tie! "
    #if opponenetChoice == str("R") and str.upper(userChoice) == "P"
    elif opponenetChoice == 'R' and userChoice.upper() == 'S':      
        print "Scissors beats rock, I win! "
        continue
    elif opponenetChoice == 'S' and userChoice.upper() == 'P':      
        print "Scissors beats paper! I win! "
        continue
    elif opponenetChoice == 'P' and userChoice.upper() == 'R':      
        print "Paper beat rock, I win! "
        continue
    else:       
        print "You win!"
Reply
#2
This looks like it is written in Python 2. That is no longer supported, and strongly suggest moving to the current version (3.8).

As far as other ideas for beginner projects, here is a site with 42 project ideas.
Reply
#3
(Aug-26-2020, 11:02 AM)jefsummers Wrote: This looks like it is written in Python 2. That is no longer supported, and strongly suggest moving to the current version (3.8).

As far as other ideas for beginner projects, here is a site with 42 project ideas.

I would recommend few more python projects which you need to go through and you can also use these source code for your final year presentation.
Reply
#4
And if you didn't already have enough suggestions, here are more ideas for python projects that you can choose from. Good luck! :)
Reply
#5
If you want to try Rock Paper Scissors Project in Python version 3, you can check out my code at https://www.youtube.com/watch?v=ItqoClNXstY
Thanks.
Reply
#6
IF you are looking for beginners python projects, please check out these 10 projects
Reply
#7
Thanks
Reply
#8
The code you've provided is a simple implementation of the Rock, Paper, Scissors game in Python. It appears to be mostly correct, but there are a few issues and improvements that can be made:

The // operator is used for floor division in Python, not for comments. Use # for comments instead.

The continue statement is used after each print statement, which is unnecessary. The continue statement is used to skip the rest of the loop and start the next iteration, but since there is no more code after the print statements, it can be omitted.

The os.system('cls' if os.name=='nt' else 'clear') line is used to clear the console screen, but it is not necessary for the functionality of the game. You can remove this line if you don't want to clear the screen.

The re module is imported but not used. You can remove the import re line if you're not using regular expressions in your code.

The userChoice variable is used as a string, but it is not converted to uppercase before comparison. You can use userChoice.upper() to convert the input to uppercase for comparison.

The opponenetChoice variable is misspelled. It should be opponentChoice.

Here is the corrected code:

import random

while True:
print("\nRock, Paper, Scissors - Shoot!")
userChoice = input("Choose your weapon [R]ock], [P]aper, or [S]cissors: ").upper()
if userChoice not in ['R', 'P', 'S']:
print("Please choose a letter: [R]ock, [S]cissors or [P]aper.")
continue
print("You chose: " + userChoice)
choices = ['R', 'P', 'S']
opponentChoice = random.choice(choices)
print("I chose: " + opponentChoice)
if opponentChoice == userChoice:
print("Tie! ")
elif (opponentChoice == 'R' and userChoice == 'S') or \
(opponentChoice == 'S' and userChoice == 'P') or \
(opponentChoice == 'P' and userChoice == 'R'):
print("I win! ")
else:
print("You win!")
This code should work correctly and is a good starting point for a beginner-level Python project. If you're looking for more project ideas try implementing a simple calculator, a weather app using an API, a to-do list, or a basic text-based adventure game.
buran write Feb-23-2024, 09:58 AM:
Spam link removed
Please, use proper tags when post code, traceback, output, etc.
See BBcode help for more info.
Reply
#9
Rock , paper scissors is much more fun using micro:bits Smile
Each player needs a mBit or use them in turn!
from microbit import *
import random

paper = Image('99999:90009:90009:90009:99999')
rock= Image('00000:09990:09990:09990:00000')
scissors= Image('90000:09099:09900:09099:90000')

while True:
    if button_a.is_pressed():
        x = random.randint(1, 3)
        if x == 1:
            display.show(paper)
        if x == 2:
            display.show(rock)
        if x == 3:
            display.show(scissors)
        sleep(4000)
        display.clear()
It is more important to do the right thing, than to do the thing right.(P.Drucker)
Better is the enemy of good. (Montesquieu) = French version for 'kiss'.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Trying to create a visual rock paper scissors game urmom33 1 976 Dec-03-2022, 09:12 PM
Last Post: deanhystad
  Rock paper scissors in python with "algorithm" Agat0 23 5,786 Mar-01-2022, 03:20 PM
Last Post: Agat0
  Problem restricting user input in my rock paper scissors game ashergreen 6 4,502 Mar-25-2021, 03:54 AM
Last Post: deanhystad
  Odd behavior with Rock Paper Scissor game DustinKlent 2 1,887 Aug-27-2020, 03:55 PM
Last Post: DustinKlent
  Trying to implement Best of 3 logic in rock paper scissors game ShAhCh 5 3,268 May-11-2020, 04:31 PM
Last Post: ShAhCh
  Rock Paper Scissors with dictionaries ewgreht 2 3,823 May-01-2020, 03:19 PM
Last Post: deanhystad
  Rock, Paper, Scissors.. Help..hidden bug xxunknownxx 4 2,605 Mar-19-2020, 02:46 AM
Last Post: jefsummers
  POS receipt print cannot make paper cut using python AP_Development 1 2,671 Dec-12-2019, 08:48 AM
Last Post: buran
  Problem with Basic Rock Paper Scissors code BirinderSingh 3 2,388 Sep-13-2019, 03:28 PM
Last Post: ichabod801
  Rock, Paper, Scissors Help jyou99 1 2,412 Mar-26-2018, 04:07 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

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