-2

I have a bad input line on some of the lines and I cant figure out how to fix it. I've been trying to get this to work for awhile and got nothing. I think I am missing a colon but I don't exactly know where.

Edit: I got the line working but 'yourChoice' isnt being defined on line 16

I tried a colon but it didn't work.

import random

def comInput():

    yourChoice = input("Rock, Paper, Scissors?")
    comChoice = random.randint(1,3)
    if comChoice == 1
        comChoice = "Rock"
    elif comChoice == 2
        comChoice = "Paper"
    elif comChoice == 3
        comChoice = "Scissors"
comInput()
def results():
    if(yourChoice == comChoice):
        print("It's a tie!")

    elif(yourChoice == "Rock" and comChoice == "Paper"):
        print("You Lose!")
    elif(yourChoice == "Rock" and comChoice == "Scissors"):
        print("You Win!")
    elif(yourChoice == "Paper" and comChoice == "Rock"):
        print("You Win!")
    elif(yourChoice == "Paper" and ComChoice == "Scissors"):
        print("You Lose!")
    elif(yourChoice == "Scissors" and comChoice == "Rock"):
        print("You Lose!")
    elif(yourChoice == "Scissors" and comChoice == "Paper"):
        print("You Win!")
results()

Tyler A
  • 21
  • 4
  • 2
    `if comChoice == 1` is missing a terminating colon `:`. You are also using `ComChoice` instead of `comChoice` in one line. Why not simply `comChoice = random.choice(["Rock", "Paper", "Scissors"])` and skip the `if/elif` cascade? A final problem, `yourChoice` is a local variable to the first function, as is `comChoice`. The second function has no access to those values. The code needs an almost complete revision. – John Coleman May 14 '19 at 18:20
  • I was able to fix it, thank you. I didn't realize I missed so much, I have been working on this code off and on due to baseball and its just hard to keep track of what I'm doing. – Tyler A May 14 '19 at 18:53

2 Answers2

2

It's missing : in those lines:

if comChoice == 1:
    comChoice = "Rock"
elif comChoice == 2:
    comChoice = "Paper"
elif comChoice == 3:
    comChoice = "Scissors"

And for your program work it, need pass comInput() result to results(). See example below:

import random


def comInput():
    yourChoice = input("Rock, Paper, Scissors?")
    comChoice = random.randint(1, 3)
    if comChoice == 1:
        comChoice = "Rock"
    elif comChoice == 2:
        comChoice = "Paper"
    elif comChoice == 3:
        comChoice = "Scissors"

    return yourChoice, comChoice


def results(yourChoice, comChoice):
    if (yourChoice == comChoice):
        print("It's a tie!")

    elif (yourChoice == "Rock" and comChoice == "Paper"):
        print("You Lose!")
    elif (yourChoice == "Rock" and comChoice == "Scissors"):
        print("You Win!")
    elif (yourChoice == "Paper" and comChoice == "Rock"):
        print("You Win!")
    elif (yourChoice == "Paper" and comChoice == "Scissors"):
        print("You Lose!")
    elif (yourChoice == "Scissors" and comChoice == "Rock"):
        print("You Lose!")
    elif (yourChoice == "Scissors" and comChoice == "Paper"):
        print("You Win!")


results(*comInput())

Revising your code, it looks was written in Java pattern style guide. Take a look in this question What is the naming convention in Python for variable and function names? and try improve your code!

Kafels
  • 3,864
  • 1
  • 15
  • 32
0

There's a typo in below line, where ComChoice was capitalised.

elif(yourChoice == "Paper" and ComChoice == "Scissors"):

checkout the below link for a beginner's approach to the game. https://thehelloworldprogram.com/python/python-game-rock-paper-scissors/

Good luck!

cristiandatum
  • 329
  • 2
  • 10