Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Rock Paper Scissors
#1
I seem to have an issue with getting this program to enter the loops correctly and the computer to generate a random number to compare against the user's input. The indenting didn't copy over correctly but I believe all of it is right.

from random import randint

def rock_paper_scissors():
w = int(input('How many rounds to win? '))
u = int(0)
c = int(0)
r = int(1)
if c or u < w:
print ('Round #', r)
ut = input('Do you throw Rock (1), Paper (2), or Scissors (3)? ')
ct = randint(1, 3)
print ('Computer threw', ct)
if ut == ct:
print (Tie)
print ('Score:'
'Computer:', c,
'User:', u)
if ut == 1 and ct == 2:
print ('Computer wins')
c += 1
r =+ 1
print ('Score:'
'Computer:', c,
'User:', u)
if ut == 1 and ct == 3:
print ('You win')
u +=1
r +=1
print ('Score:'
'Computer:', c,
'User:', u)
if ut == 2 and ct == 1:
print ('You win')
u += 1
r += 1
print ('Score:'
'Computer:', c,
'User:', u)
if ut == 2 and ct == 3:
print ('Computer wins')
c += 1
r += 1
print ('Score:'
'Computer:', c,
'User:', u)
if ut == 3 and ct == 1:
print ('Computer wins')
c += 1
r +=1
print ('Score:'
'Computer:', c,
'User:', u)
if ut == 3 and ct == 2:
print ('You win')
u += 1
r += 1
print ('Score:'
'Computer:', c,
'User:', u)
if c == w:
print ('Computer wins')
if u == w:
print ('You win')

def main():
print('ROCK PAPER SCISSORS in Python')
print()
print('Rules: 1) Rock wins over Scissors.')
print(' 2) Scissors wins over Paper.')
print(' 3) Paper wins over Rock.')

rock_paper_scissors()

main()
Reply
#2
We can't see the loops or the conditionals correctly without the indentation. Please repost your code with python tags. See the BBCode link in my signature below for instructions.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
from random import randint

def rock_paper_scissors():
w = int(input('How many rounds to win? '))
u = int(0)
c = int(0)
r = int(1)
if c or u < w:
print ('Round #', r)
ut = input('Do you throw Rock (1), Paper (2), or Scissors (3)? ')
ct = randint(1, 3)
print ('Computer threw', ct)
if ut == ct:
print (Tie)
print ('Score:'
'Computer:', c,
'User:', u)
if ut == 1 and ct == 2:
print ('Computer wins')
c += 1
r =+ 1
print ('Score:'
'Computer:', c,
'User:', u)
if ut == 1 and ct == 3:
print ('You win')
u +=1
r +=1
print ('Score:'
'Computer:', c,
'User:', u)
if ut == 2 and ct == 1:
print ('You win')
u += 1
r += 1
print ('Score:'
'Computer:', c,
'User:', u)
if ut == 2 and ct == 3:
print ('Computer wins')
c += 1
r += 1
print ('Score:'
'Computer:', c,
'User:', u)
if ut == 3 and ct == 1:
print ('Computer wins')
c += 1
r +=1
print ('Score:'
'Computer:', c,
'User:', u)
if ut == 3 and ct == 2:
print ('You win')
u += 1
r += 1
print ('Score:'
'Computer:', c,
'User:', u)
if c == w:
print ('Computer wins')
if u == w:
print ('You win')

def main():
print('ROCK PAPER SCISSORS in Python')
print()
print('Rules: 1) Rock wins over Scissors.')
print(' 2) Scissors wins over Paper.')
print(' 3) Paper wins over Rock.')

rock_paper_scissors()

main()
Reply
#4
We still cannot see the indentation. Please read my previous post carefully.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#5
Please write [python] before you paste your code into a post, and then write [/python] after your code is pasted.

(If you prefer, you can paste your code, select it, and then click the python icon in the formatting bar of the post entry dialogue box to enter the start and finish tags for you.)

This will preserve the layout of your code as written in your text editor / IDE, with all the indentations that are critical to python displayed normally.

Without this, the indentations are messed up when you paste code, and we are not as easily able to see where problems might be.

(Oct-06-2017, 02:08 AM)Warmlawpk441 Wrote: I seem to have an issue with getting this program to enter the loops correctly and the computer to generate a random number to compare against the user's input. ...

I cannot see any loops in your code.

Loops will use constructs such as: for play in numberofplays:, where numberofplays is an integer variable holding the number of rounds, or while playing:, where playing is a boolean variable used to indicate whether the game should continue or not.

Here's an example, throwing two dice (python 3):

(Note. In this example, the while statement evaluates an expression to get a True or False outcome to decide whether or not the indented code below the while statement should be executed or not.)

import random
min = 1
max = 6

roll_again = "yes"

while roll_again == "yes" or roll_again == "y":
    print("Rolling the dices...")
    print("The values are....")
    print(random.randint(min, max))
    print(random.randint(min, max))

    roll_again = input("Roll the dices again?")
I am trying to help you, really, even if it doesn't always seem that way
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  I attempted to make a rock paper scissors bot for homework Intellectual11 3 2,925 Jun-24-2021, 08:00 PM
Last Post: deanhystad
Question Rock, paper, scissors spelling error banidjamali 6 3,224 Jan-19-2021, 02:51 PM
Last Post: banidjamali
  Rock, Paper, Scissors Game kramon19 2 5,362 Jan-10-2020, 08:18 AM
Last Post: perfringo
  I need help with a python Rock Paper Scissors game urgently. Riff_Raff 3 5,856 Dec-05-2018, 09:13 PM
Last Post: nilamo
  Rock, Paper, Scissors Advanced that saves, loads, and keeps statistics EvanCahill 0 5,214 Jul-21-2018, 07:32 PM
Last Post: EvanCahill
  Rock paper scissors game samiraheen 3 6,372 Oct-03-2017, 07:07 PM
Last Post: buran
  The Python Book altered rock paper scissors Python_Noob 0 2,922 Sep-18-2017, 06:13 AM
Last Post: Python_Noob
  HELP---problems with rock paper scissors games kalt91 2 4,131 Sep-15-2017, 04:51 PM
Last Post: micseydel
  Rock, Paper, Scissors game help.. hentera 3 5,064 May-19-2017, 10:56 PM
Last Post: ichabod801
  Rock Paper Scissors game codeobri 3 13,419 Apr-28-2017, 01:02 AM
Last Post: codeobri

Forum Jump:

User Panel Messages

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