The game works, but I was wondering if anyone could help me with better structure for the code, simplification, or just any other improvements.
from random import randrange
# assigns the amount of turns and starts the program
def Main():
print "~A game of Scissors, Paper, Rock!~"
global turns
turns = raw_input("How many times do you want to play? : ")
# tests for int input and restarts if not an int
try:
turns = int(turns)
print "\nYou will play", turns, "turn(s) against the computer! \n"
play()
except ValueError:
print "That's not a valid input! Integers only, please! \n"
Main()
#determines the player's choice and sets the computers choice
def play():
global options
options = {1: "Scissors", 2: "Paper", 3: "Rock"}
global turns
# loops for different choices, and calls the comparison function
while turns > 0:
try:
global pchoice
pchoice = int(raw_input("Choose one! \n <1> Scissors \n <2> Paper \n <3> Rock \n"))
global cchoice
cchoice = randrange(1,4)
comparison()
except KeyError:
print "an invalid input! Please try again. \n"
play()
turns -= 1
# compares player's choice with the computer's and returns a tie, win, or loss
def comparison():
print "You chose:", options[pchoice], "and the computer chose:", options[cchoice]
if int(pchoice) == cchoice:
print "A tie! \n"
elif pchoice == 1 and cchoice == 3 or pchoice == 2 and cchoice == 1 or pchoice == 3 and cchoice == 2:
print "You lose! \n"
else:
print "You win! \n"
Main()