Problems with Rock, Paper, Scissors Python Code - python

I'm working on a code with python, where we've been asked to create a game of Rock, Paper, Scissors using an external file of options (rock, paper, scissors) as opposed to having the code use any user input. However, for some reason, my code doesn't work. When someone inputs "yes", it prints "Let us play now," but that's it. Nothing else happens.
Why isn't the game completing when a user provides "yes" as input?
from random import randrange
def sample():
computer_input = randrange(1,3)
return computer_input
def main():
a = []
infile = open("input2.txt", "r")
for line in infile:
a.append(line)
computer_input = sample()
tied = 0 #games tied
user_won = 0 #games won by user
comp_won = 0 #games won by computer
user_input = ""
computer_input = ""
print("Rules of the game...")
print("Would you like to turn up with a game of rock, paper, or scissors? ;) Yes or no? -->")
answer = input()
if (answer == "yes"):
play = True
print("Let us now play.")
## elif(answer == "no" or "No"):
## play = False
## print("Sorry. Maybe we can play next time ;)")
## else:
## play = False
## print("Please try again!")
## main()
while True:
if(computer_input == "1"):
if(user_input == a[0]):
tied = tied + 1
print("Game is tied!")
elif(user_input == a[1]):
user_won = user_won + 1
print("You won! Paper covers Rock")
elif(user_input == a[2]):
comp_won = comp_won + 1
print("You lost! Rocks knocks out scissors")
## else:
## print("Try again!")
elif (computer_input == "2"):
if (user_input == a[0]):
comp_won = comp_won + 1
print("You lost! Paper covers Rock")
elif(user_input == a[1]):
tied = tied + 1
print("Game is tied!")
elif(user_input == a[2]):
user_won = user_won + 1
print("You won! Scissors cuts Paper")
## else:
## print("Try again!")
else :
if(user_input == a[0]):
user_won = user_won + 1
print("You won! Rock knocks out scissors")
elif(user_input == a[1]):
comp_won = comp_won + 1
print("You lost! Scissors cuts Paper")
elif(user_input == a[2]):
tied = tied + 1
print("Game is tied!")
## else:
## print("Try again!")
##
##print("Game over")
##print("Statistics")
##print("Games tied -->", tied)
##print("Game won by comp -->", comp_won)
##print("Game won by user -->", user_won)
##
main()

Notice that on line 5 below, you set computer_input to the result of sample():
def main():
a = []
infile = open("input2.txt", "r")
for line in infile:
a.append(line)
computer_input = sample()
But then a few lines later, you set it to "":
user_input = ""
computer_input = ""
Your while loop is checking against the value of computer_input, but it assumes it will be a number. It has no case to handle the empty string. I would recommend removing that line.
Also note that your while loop is checking the value of user_input, but you never seem to actually read input into that variable.

There are many, many problems with this code.
Every time you define or use a variable, you should have a clear idea of
why it is defined this way or exactly what this use of the variable is
going to accomplish.
You have a loop, which seems to indicate that you meant for more than
one round of the game to be played when you run the code once.
But there is only one place where the computer's choice is set
to a number 1, 2, or 3, and it occurs only once.
(Besides, as has already been pointed out, then you change the
computer's choice to "" without even reading the number once.)
You have no apparent way to get out of the loop within the logic of the code.
It is unclear what you think you are supposed to be reading from the
user's input file. You put the contents of the file in the array a line
by line, but then you only ever look at a[0], a[1], and a[2].
What were the first three lines of the file supposed to contain?
Why only three lines? What does it mean to ask whether
user_input == a[0]?
(I have a hunch that you were supposed to set the user input on each
round to a member of a, not compare user_input to a member of a.)
(Also notice that you set user_input = "" earlier, so unless you read
empty strings into the entries of a, expressions like
user_input == a[0] will always be false.)
What is the point of setting play = True? (Or even setting
play = False as in the commented-out code?) You never do anything that
would read the value of play.
What is the point of keeping count in the variables tied,
user_won, and computer_won? You never read those variables either,
except when you're setting new values of them.
It might help if you write some smaller functions with very clear
purpose, input and output. The sample() function is promising, but
everything else is in main().
For example, figuring out who won, given the computer's choice and
the player's choice, could be a function.
By writing such a function you would remove dozens of lines of code from
the loop in main(), replacing them with perhaps one line of code.
It's much, much easier to write well-designed loops when
the block of code inside the loop is short.

Related

How to make a helper function work - please see code below

I'm trying to make a rock, paper, and scissors game that receives input from a user that plays against a robot that randomly selects rock, paper, or scissors. Here is my main() code:
"""
Name: Scott Houston
Date: January 19th, 2021
Program Description: Game of classic rock, paps
"""
import random
import gameFunctions2
def main():
while True:
computer_move = random.randint(1, 3)
print("Welcome to rock, paper, scissors! Rock beats scissors, scissors beats paper,"
" and paper beats rock. ")
user_input = input("Press 'A' for rock, 'B' for paper, and 'C' for scissors!\n"
"A. Rock\n"
"B. Paper\n"
"C. Scissors\n")
if gameFunctions2.tie(user_input, computer_move) == False:
if user_input == "A" or user_input == "a":
if computer_move == 2:
print("Your opponent has chosen paper! Paper wraps rock! You lose! ")
else:
print("Your opponent has chosen scissors! Rock breaks scissors! You win! ")
elif user_input == "B" or user_input == "b":
if computer_move == 3:
print("Your opponent has chosen scissors! Paper is cut by scissors! You lose! ")
else:
print("Your opponent has chosen rock! Paper wraps rock! You win! ")
elif user_input == "C" or user_input == "c":
if computer_move == 1:
print("Your opponent has chosen rock! Scissors loses to rock! You lose! ")
else:
print("Your opponent has chosen paper! Scissors beats paper! You win! ")
if gameFunctions2.input_detection(user_input) == True:
print()
else:
print()
user_play_again = input("Would you like to play again? Type 'y' if you'd like to play again. ")
if user_play_again == "y":
print()
else:
print("Have a great day! ")
break
# Calls the Main Function
main()
Here is my helper function (gameFunctions2):
def input_detection(user_input):
if user_input == "A" or user_input == "a" or user_input == "B" or user_input == "b" or user_input == "C" or user_input == "c":
return True
else:
print("Please enter a valid option! ")
return False
def tie(user_input, computer_move):
if user_input == user_input.lower in ["a"] and computer_move == "1":
print("It's a tie!")
return True
if user_input == user_input.lower in ["b"] and computer_move == "2":
print("It's a tie!")
return True
if user_input == user_input.lower in ["c"] and computer_move == "3":
print("It's a tie!")
return True
else:
return False
The problem that I'm facing right now is that there will never be a tie between the user and the computer. I've tried to implement the function tie(user_input, computer_move) into main(), but to no success. I have to use helper functions for this assignment, so I'm trying my best to do so. Also, if there's any place that I can make my code more efficient, it would be fantastic if you could point out where :))
Change your tie function to this:
def tie(user_input, computer_move):
if user_input.lower() == "a" and computer_move == 1:
print("It's a tie!")
return True
elif user_input.lower() == "b" and computer_move == 2:
print("It's a tie!")
return True
elif user_input.lower() == "c" and computer_move == 3:
print("It's a tie!")
return True
else:
return False
You cant compare String and Int like this: computer_move == "1" when computer_move is Int.
Simplify the user_input.lower() == "a" statement.
Here is what you can use to make your code more readable:
Use dictionary to translate users input into integers.
Then you can also easily check all the conditions.
Here is the code (I have only added the part where I have get rid of the tie function):
import random
choose = "Start"
symbols = {"rock":1, "paper":2, "scissors":3}
while True:
choose = input("Hi welcome to my game! Choose between Rock, Paper, Scissors! End the game with 'End':\n")
choose = choose.lower()
computer = random.randint(1,3)
if choose in symbols: #Check if input is in a string and if its in symbols
choose = symbols[choose]
elif choose == "end":
break
else:
print("You have written down something ... weird ... next round.")
continue
if choose == computer:
print("It's a tie!")
else:
#Choose who wins ...
pass
There are a lot of minor issues in your code that can be streamlined and a few major ones, but the one causing your issues is that you are defining computer_move as an integer in the main function (computer_move = random.randint(1, 3)), but in your tie function, you are comparing it to a string (eg, computer_move == "1") The first half of your if statement also is not doing what you want: Rewrite that function as such:
def tie(user_input, computer_move):
if user_input.lower() == "a" and computer_move == 1:
print("It's a tie!")
return True
if user_input.lower() == "b" and computer_move == 2:
print("It's a tie!")
return True
if user_input() == "c" and computer_move == 3:
print("It's a tie!")
return True
else:
return False
If you don't want to have a different if statement for each possible outcome, you can try this:
def outcomes(user_input, computer_move):
end_states = {"tie": [["a", 1], ["b",2], ["c",3]],
"user_win": ["LISTS OF USER WIN STATES"]}
if [user_input.lower(), computer_move] in end_states["tie"]:
print("tie")
if [user_input.lower(), computer_move] in end_states["user_win"]:
print("user wins")
else:
print("computer wins")
A few of the fixes:
user_input = input("Press 'A' for rock, 'B' for paper, and 'C' for scissors!\n"
"A. Rock\n"
"B. Paper\n"
C. Scissors\n")
can be changed to:
user_input = input("Press 'A' for rock, 'B' for paper, and 'C' for scissors!\n"
"A. Rock\n"
"B. Paper\n"
C. Scissors\n").lower()
so that you don't need to check for both upper and lower cases each time (you would also be able to remove .lower() from the tie function.
You should move the input_detection function to right after the user makes the input, and you can rewrite the check as such:
if not gameFunctions2.input_detection(user_input):
continue
Which roughly translates to, if it returns "False", return to the start of your while loop (You can also remove the checks for uppercase and lowercase letters, if you use the previous edit).
For checking if the player wants to play again, add .lower() to the end of the input, and you can change the last lines as such:
if user_play_again != "y":
print("Have a great day! ")
break
You don't need to have a statement that evaluates if user_play_again == "y" just to have the else statement (unless you want there to be a separate action for it). You can evaluate the opposite (if user_play_again != "y") alone.
As I began to do earlier, you can put each ending variation into dictionaries and instead of having a different line for each end state check, you can evaluate the dictionary as a whole to streamline things a bit too.
These might not be the only things, and others might disagree with my changes, but it's a start of how I would rewrite the code.
The other answers have resolved the bugs in your code. This answer is meant to give you some ideas about how you might do things differently - specifically, a more object-oriented approach, and taking advantage of the standard library a bit more.
from enum import Enum
class Move(Enum):
ROCK = 0
PAPER = 1
SCISSOR = 2
def get_user_move():
moves = dict(zip("ABC", Move))
print("Options:")
for option, move in moves.items():
print(f"{option:>5}. {move.name.title()}")
prompt = "Enter your selection: "
while True:
user_input = input(prompt).upper()
if user_input in moves:
break
prompt = "Try again: "
return moves[user_input]
def main():
from random import choice
while True:
user_move = get_user_move()
computer_move = choice(tuple(Move))
print(f"\nYou picked {user_move.name.title()}")
print(f"The computer picked {computer_move.name.title()}")
if user_move is computer_move:
print("It's a tie!\n")
else:
winner = ("The computer", "You")[(computer_move.value + 1) % len(Move) is user_move.value]
print(f"The winner is: {winner}!\n")
return 0
if __name__ == "__main__":
import sys
sys.exit(main())

How do I add a 'play again' option for the following game [duplicate]

This question already has answers here:
Is 'input' a keyword in Python?
(2 answers)
Call built-in function if overwritten by a variable of the same name
(3 answers)
Using function names as variables in python
(2 answers)
Closed 2 years ago.
I have tried to add a 'while True' loop but it shows the error 'str object is not callable'. Please help me on this one. I need an extension of this already written code game.
import random
user_score = 0
computer_score = 0
user_score = 0
computer_score = 0
input = input("Choose your move, Rock, Paper or Scissors: ").upper()
comp = ["ROCK", "PAPER", "SCISSORS"]
computer_move = random.choice(comp)
if input == "ROCK":
if computer_move == "PAPER":
print("You lost. Better luck next time!")
computer_score += 1
elif computer_move == "SCISSORS":
print("You won! Well done.")
user_score += 1
elif input == "PAPER":
if computer_move == "ROCK":
print("You won! Well done.")
user_score += 1
elif computer_move == "SCISSORS":
print("You lost. Better luck next time!")
computer_score += 1
elif input == "SCISSORS":
if computer_move == "ROCK":
print("You lost. Better luck next time!")
computer_score += 1
elif computer_move == "PAPER":
print("You won! Well done.")
user_score += 1
elif input == computer_move:
print("It's a tie!")
print(f"Your Score: {user_score} ; Computer Score: {computer_score} ")
This is happening because you are defining your input variable as this:
input = input("Choose your move, Rock, Paper or Scissors: ").upper()
input is a built-in function in python, don't use variables with keywords/built-in functions as names.
In your second iteration inside the while, when you try to take input with the input() function, it gives an error since you overshadowed it with your string input (Python is dynamically-typed) so it's no longer the function <built-in function input> which could help you take the input in current scope. You can define it like this:
choice = input("Choose your move, Rock, Paper or Scissors: ").upper()
You can try something like this:
while(True):
# your code
answer = input("Do you want to play again? (y / n): ")
if (answer == "n") break
With this code, the player will be asked to input either "y" or "n". If the answer is anything different than "n", the game will re-start. Otherwise it will not (the program will break out of the loop).
the problem you encountered resulted from naming the variable holding the user input input thus when using the function input the secon time it instead tried calling the variable holding the string of the previous use of input.
change the name of the variable input to something different like user_input and then looping should work.

Unable to verify user input in game

I am creating a rock, paper, scissors game. I want it to be best of 3 matches and to be able to verify user input. I keep running into issues with the user input. I have tried multiple variations but I can't seem to figure it out. I know my code is probably messy, so any input on how to clean it up would be greatly appreciated. Thank you so much for your time.
import random
import sys
import time
print("Hello and welcome to the Rock, Paper, Scissors tournament.\n"
"The tournament will be the best of 3 wins.\n"
"It will be you against our highly intelligent computer opponent.\n"
"Good luck!")
# Create a function for the game
def play_game():
user_count = 0
comp_count = 0
tie_game = 0
while comp_count < 2 and user_count < 2:
user_choice = (int(input("-------------------------------------------"
"\nEnter choice by typing 1 2 or 3: \n 1. Rock \n 2. paper \n 3. scissor \n"
"-------------------------------------------\n")))
if user_choice == 1:
user_choice_name = 'Rock'
elif user_choice == 2:
user_choice_name = 'Paper'
elif user_choice == 3:
user_choice_name = 'Scissor'
else:
print("Please pick a valid number")
print(f"\nYou have chosen: {user_choice_name}")
print("\nNow it's the computer's turn to pick......")
time.sleep(3)
comp_choice = random.randint(1, 3)
if comp_choice == 1:
comp_choice_name = 'Rock'
elif comp_choice == 2:
comp_choice_name = 'Paper'
else:
comp_choice_name = 'Scissor'
print(f"\nComputer has chosen: {comp_choice_name}\n")
if user_choice == 1 and comp_choice == 2:
comp_count += 1
print("Computer wins this round with Paper! "
f"\n Computer: {comp_count}"
f"\n You: {user_count} \n\n")
elif user_choice == 1 and comp_choice == 3:
user_count += 1
print("You win this round with Rock!"
f"\n Computer: {comp_count}"
f"\n You: {user_count} \n\n")
elif user_choice == 2 and comp_choice == 1:
user_count += 1
print("You win this round with Paper!"
f"\n Computer: {comp_count}"
f"\n You: {user_count} \n\n")
elif user_choice == 2 and comp_choice == 3:
comp_count += 1
print("Computer wins this round with Scissor!"
f"\n Computer: {comp_count}"
f"\n You: {user_count} \n\n")
elif user_choice == 3 and comp_choice == 2:
user_count += 1
print("You win this round with Scissor!"
f"\n Computer: {comp_count}"
f"\n You: {user_count} \n\n")
elif user_choice == 3 and comp_choice == 1:
user_count += 1
print("Computer wins this round with Rock!"
f"\n Computer: {comp_count}"
f"\n You: {user_count} \n\n")
else:
if user_choice == comp_choice:
tie_game += 1
print(f"This round was a tie! Both choosing {user_choice_name}, try again!"
f"\n Computer: {comp_count}"
f"\n You: {user_count} \n\n")
else:
print(f'The game is now over with a score of: \n You:{user_count} \n to \n Computer:{comp_count}')
again = str(input("Do you want to play again, type 'yes' or 'no' \n"))
if again.lower() == "no":
print('Thank you for playing!')
sys.exit()
else:
play_game()
play_game()
Since I had a few minutes to kill with a cup of coffee, here's a rewrite of your program with a bunch of improvements, the validation you asked about and some tips on coding style:
import random
import time
print("Hello and welcome to the Rock, Paper, Scissors tournament.\n"
"The tournament will be the best of 3 wins.\n"
"It will be you against our highly intelligent computer opponent.\n"
"Good luck!")
# to avoid repeating these values over and over and changing numbers in to string,
# just defining them here. Name in capitals because it's global (generally bad)
# an even nicer solution would be to write a Game() class and put everything in
# there, but it would be a bit more advanced
RSP_OPTIONS = {
1: 'Rock',
2: 'Scissor',
3: 'Paper'
}
def get_user_choice():
# keep asking until a valid value is returned
while True:
# this is a bit fancy, but let's say you want to reuse the game for similar games
# with different options from rock, scissor, paper, you'd want this code to still work
# get a list of string versions of the numbers
numbers = list(map(str, RSP_OPTIONS.keys()))
# join them together like you presented them: 1, 2 or 3
options = ', '.join(numbers[:-1]) + ' or ' + numbers[-1] + ':\n'
# add the descriptions
options = options + ''.join(f'{n}: {name}\n' for n, name in RSP_OPTIONS.items())
try:
user_choice = (int(input("-------------------------------------------\n"
f"Enter choice by typing {options}"
"-------------------------------------------\n")))
except ValueError:
# any invalid option
user_choice = -1
# check if it's one of the valid options
if user_choice in RSP_OPTIONS:
return user_choice
else:
# it makes sense to generate a new line where you want it, instead of having
# to put new line characters at the start of other strings
print("Please pick a valid number\n")
def beats(choice1, choice2):
# choice1 beats choice2 if it's one greater, except when choice2 == 3 and choice1 == 1
# but to make it even nicer and have it work for other similar games, you could say
# "except when choice1 == the max choice and choice2 == the min choice"
return (choice2 - choice1 == 1 or
(choice1 == max(RSP_OPTIONS.keys()) and choice2 == min(RSP_OPTIONS.keys())))
# Create a function for the game
def play_game():
user_count = 0
comp_count = 0
tie_game = 0
# this is what you really want, best out of three, ties not counted?
while comp_count + user_count < 3:
user_choice = get_user_choice()
print(f"You have chosen: {RSP_OPTIONS[user_choice]}\n")
print("Now it's the computer's turn to pick......\n")
# this wait is not very nice, the user might try to hit enter or something
# you could consider printing the countdown, or telling the user to please wait
# even then, it's kind of silly to pretend the computer has to work hard here
time.sleep(3)
# this choice is always valid, so no problem
comp_choice = random.randint(1, 3)
# note that you don't need the name, you can just look it up whenever in RSP_OPTIONS
print(f"\nComputer has chosen: {RSP_OPTIONS[comp_choice]}\n")
# getting rid of some repetition, note how the code really reads like what is intended
if beats(comp_choice, user_choice):
comp_count += 1
# nice to also say what really beat them
print(f"Computer wins this round with {RSP_OPTIONS[comp_choice]} over {RSP_OPTIONS[user_choice]}!\n")
elif beats(user_choice, comp_choice):
user_count += 1
print(f"You win this round with {RSP_OPTIONS[user_choice]} over {RSP_OPTIONS[comp_choice]}!\n")
else:
# you can only get here on a tie
tie_game += 1
print(f"This round was a tie! Both choosing {RSP_OPTIONS[user_choice]}, try again!\n")
# you always print this, so just do it after the options:
print(f"Computer: {comp_count}\n"
f"You: {user_count}\n\n")
else:
print(f'The game is now over with a score of:\n You:{user_count}\n to\n Computer:{comp_count}\n')
again = str(input("Do you want to play again, type 'yes' or 'no' \n"))
# let's quit on anything starting with n
if again.lower()[0] == "n":
print('Thank you for playing!\n')
# instead of exiting hard, maybe just return, telling the caller we don't want to play again
return False
else:
# you were calling play_game again, but that causes the game to get more and more calls
# on top of each other, ultimately reaching an error state
# by returning first and then calling again, you avoid that problem
return True
# the function returns whether it should play again
while play_game():
pass
# once it leaves the loop, the game stops automatically here, no more code
There's still a lot of room for improvement though; try implementing some more advanced forms of RSP, or make the computer more intelligent than just playing random, but have it use some kind of strategy, perhaps with a bit of randomness mixed in.
And code-wise, try separating the game from the way it is presented on the screen; what if you decided to do this on the web instead of on a console, or in a graphics window? You could also consider putting all the code in a nice class, getting rid of global variables and allowing you to create more copies of the game as needed.

Python is ignoring fleeing_attempted variable

I am making a fighting system for a text-based game I am working on, and one option is to flee.
however, I want to make it so that you can only attempt to flee once. I made it so that after 1 failed attempt, the variable fleeing_attempted is set from false to true. However, python is ignoring this and letting me attempt to flee as many times as I want.
edit: I made fixes, but the result hasn't changed. here are the modifications.
fleeing_attempted = False #the first time the variable is defined
def battle():
print("What will you do?")
print("1. attack")
print("2. flee")
action = input()
if action == "1":
print("test")
elif action == "2":
fleeing = randint(1, 100)
if fleeing in range(1, 50):
print("You got away!")
elif fleeing in range(51,100):
callable(fleeing_attempted)
print("The enemy caught up!")
battle()
elif action == 2 and fleeing_attempted:
print("You already tried that!")
battle()
Take a look at the following two lines of code:
fleeing_attempted = False
if fleeing_attempted == True:
There is no chance for fleeing_attempted to ever be True at that if statement, since it is being set to False on the line above.
Without seeing the rest of your code, it is hard to tell where the fleeing_attempted=False should go but it should probably be somewhere in initialization.
elif action == "2":
fleeing = randint(1, 100)
fleeing_attempted = False < --- Your problem is here.
if fleeing_attempted == True:
You set it to False before you do the if check, so it will never be True.
You can also do:
if fleeing_attempted:
to test if it's true.
You can also clean up your code with and
elif action == "2" and fleeing_attempted :
# rest of code
Cleaned Code:
def have_battle():
action = input("What will you do?")
print("1. Attack")
print("2.Flee")
if action == "1":
print("You choose to attack")
elif action == "2":
# do your random check
fleeing = random.randint(0, 100)
print("fleeing variable: {0}", fleeing)
if fleeing in range (1,50):
print("You choose to flee")
You had some major problems, but I cleaned up some it and you should be able to work off it.

What's wrong with the indentation? Python, Rock Paper Scissors Game

These are the instructions: This program should be written using a menu driven interface. It should contain at least 6 functions, as follows (you can have more if you think you need others). You should choose descriptive function names to properly describe their function (follow the convention for properly naming functions). Just to be clear, you should NOT have functions called function1, function2, etc. Replace the names below with your own function names in your code.
When I run it, I get an error code saying "expected an indented block" for the line if comp(==1 and user ==3).
Please let me know what's wrong, thanks!
#import random module
import random
#main function
def main():
#program message
print("Rock, Paper, Scissors Game")
#initializing variables that would hold choices of user and computer
comp = 1
user = 1
while comp == user:
print("Enter your choice in range from 1 to 3")
#prompt user to enter choice
user = int(input("Your choice: "))
#randomly assign choice to computer
comp = random.randint(1,3)
#display choice of computer
print("Computer Choice : ",comp)
#display game drawn message, when same choices
if (comp == user):
print("Game Drawn. Select again")
#calling function to decide winner
winner (comp, user)
#winner function
def winner(comp, user):
#rock and scissor choice
if(comp == 1 and user ==3):
print("Computer win")
print("The rock smashes scissor")
elif(comp == 3 and user ==1):
print("User win")
print("The rock smashes scissor")
else:
#paper and rock choice
if(comp == 1 and user == 2):
print("User win")
print("The paper wraps rock")
elif (comp == 2 and user ==1):
print("Computer win")
print("Scissors cut paper")
elif (comp == 2 and user == 3):
print("User win")
print("Scissors cut paper")
else:
print("Invalid selection")
#calling main function
main()
Besides the answer from Nathaniel Ford, your if-elif-else indendation is wrong at some places as well.
if (condition):
print "hi"
elif (condition):
print "hi again"
else:
print "hi again vol3"
This is the correct way to indendent if-elif-else conditions.
The problem is with the previous code line:
def winner(comp, user):
def is defining a function, and expects that function to have a body. Because you back the indentation out to the top level, the def body has nothing (not even a pass), and thus won't compile.
But note that isn't your only indentation problem. The definition of main prints one line print("Rock, Paper, Scissors Game"), and then sets some variables and... quits. Because the indentation of while comp == user: backs out a level, it doesn't exist inside the main definition. This a problem with pretty much every new block of your code. You should read up how Python structures code with indentation.

Categories

Resources