Sep-13-2019, 12:21 PM
Guys I just started with python a couple days back, and today finally sat down to write a code for Rock Paper Scissors.
The code abruptly ends after just executing game() function. Many other codes I checked closely resembled mine, but they worked and my doesn't. The problem seems to be with the Randomization, since in my testing everything works except for it. Any help would be greatly appreciated. I know the code is a bit too long for such a simple game, but i don't need to know how to shorten it (will save it for later), just what is causing the problem right now.
Thanks
The code abruptly ends after just executing game() function. Many other codes I checked closely resembled mine, but they worked and my doesn't. The problem seems to be with the Randomization, since in my testing everything works except for it. Any help would be greatly appreciated. I know the code is a bit too long for such a simple game, but i don't need to know how to shorten it (will save it for later), just what is causing the problem right now.
Thanks
from os import system, name
from time import sleep
from random import randint
rps = None
cpu = None
ai = None
def strt():
print("Rock Paper Scissors")
sleep(1)
def game():
global rps
global cpu
global ai
rps = input("Choose Rock (r), Paper (p), or Scissors (s)")
if rps != "r" and rps != "p" and rps != "s":
print("Invalid function, starting over...")
sleep(1)
game()
else:
cpu = randint(1, 3)
ai = cpu
if cpu == "1":
ai = "r"
elif cpu == "2":
ai = "p"
elif cpu == "3":
ai = "s"
decision()
def decision():
if rps == ai:
print("Decision Neutral")
game()
elif rps == "r":
if ai == "s":
print("you win")
elif ai == "p":
print("you lose")
elif rps == "p":
if ai == "s":
print("you lose")
elif ai == "r":
print("you win")
elif rps == "s":
if ai == "r":
print("you lose")
elif ai == "p":
print("you win")
strt()
game()
