Python Forum

Full Version: Rock Paper Scissors
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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()
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.
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()
We still cannot see the indentation. Please read my previous post carefully.
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?")