+ 1

Why I am getting the error as return outside the function? Plz correct me where I made the mistake

https://code.sololearn.com/c0zLJYD4mchD/?ref=app

28th Jul 2021, 8:50 AM
Kartik Mishra
3 Answers
+ 2
import random def gamewin(comp,you): if comp == you: return None if comp == 's': if you == 'g': return True elif you == 'w': return False if comp == 'w': if you == 'g': return False elif you == 's': return True if comp == 'g': if you == 's': return False elif you == 's': return True comp='w' print("comp's turn:snake(s),water(w) or gun(s)") random_number = random.randint(1,3) if "random_number" == 1: comp = 's' elif "random_number" == 2: comp = 'w' elif "random_number" == 3: comp = 'g' you = input("your turn: snake(s),water(w) or gun(g)") a = gamewin("comp",you) print(f'computer chose {comp}') print(f"you chose {you}") if a == "None": print("the game is a tie!") elif a: print("you win!") else: print("you lose! better luck next time!!")
28th Jul 2021, 9:00 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 1
you have written all things outside from function. u need to write if esle statement inside . And also your comp variable is undefined i have defined with w char u can change it. see this one it will work............---->
28th Jul 2021, 9:00 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 1
Thank you so much
28th Jul 2021, 9:04 AM
Kartik Mishra