T8y8 Posted May 2, 2008 Share Posted May 2, 2008 I recently started teaching myself python (after searching the threads for recommendations). Right now I am working on a Rock, Paper, Scissors program to mess around with if...then, definitions, and booleans, which is why the program might seem odd, I have the WIN/LOSE based off of Bool's, but I wanted to practice using them. Right now I'm trying to figure out a way to integrate a check to see if the player is actually putting in rock, paper, or scissors, but I haven't gotten anything to work yet. I have it checking for membership in the list picks, but I'm not sure how to make that 'reset' or try again. Any ideas? #!/usr/bin/env python # filename : rps.py # Author: T8y8 # A Rock, Paper, Scissors game #Imports import random import sys #Define Variables menu = ''' ================================= Welcome to Rock, Paper, Scissors! Press enter to continue Quit at anytime by typing 'quit' ================================= ''' picks = ['rock', 'paper', 'scissors'] #Computer Chooses def computerPick(): global compChoice compChoice = random.choice(picks) #Player Chooses def playerPick(): global playerChoice playerChoice = raw_input("Rock, Paper, or Scissors?") if playerChoice.lower() == 'quit': sys.exit() if playerChoice.lower() not in picks: print ' That is not an option' def choiceCompare(x, y): # X is Comp, Y is Person global win win = False if not win: if x == 'rock': if y.lower() == 'paper': win = True elif x == 'paper': if y.lower() == 'scissors': win = True elif x == 'scissors': if y.lower() == 'rock': win = True #Show menu c = raw_input(menu) # Game Loop while c != 'quit': computerPick() playerPick() choiceCompare(compChoice, playerChoice) if win is True: print "You beat %s with %s" % (compChoice, playerChoice) elif playerChoice == compChoice: print "YOU TIED WITH %s" % compChoice else: print "You lost to %s with %s" % (compChoice, playerChoice) Quote Link to comment Share on other sites More sharing options...
SomeoneE1se Posted May 2, 2008 Share Posted May 2, 2008 try the code with out using functions. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.