Jump to content

My crack at python


Recommended Posts

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

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':
    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':
        choiceCompare(compChoice, playerChoice)
        if win is True:
            print "You beat %s with %s" % (compChoice, playerChoice)
        elif playerChoice == compChoice:
            print "YOU TIED WITH %s" % compChoice
            print "You lost to %s with %s" % (compChoice, playerChoice)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...