0

I am having a bit of trouble with my whoWins function and my menue. i can get all of my other functions to run from main but whoWins just doesnt seem to want to work no matter what i try.i am also unsure if the dictionaries etc for the whoWins function are to be placed inside the function or left at the top of the program. i am also unsure if i have correctly placed my program in the autopicks function for the menue. i think t might be an indentation problem or something like that. any help will be greatly appreciated. cheers heaps joel

import random
import string
Ascore = 0
Bscore = 0
Dscore = 0
table = {1:"Rock", 2:"Paper",3:"Scissors"}

turnTuple = ()

Awins = {(2,1):"Paper beats rock - Player A wins",
         (1,3):"Rock beats scissors - Player A wins",
         (3,2):"Scissors beat paper - Player A wins."}

Bwins = {(1,2):"Paper beats rock - Player B wins",
         (3,1):"Rock beats scissors - Player B wins",
         (2,3):"Scissors beat paper - Player B wins."}

Cdraws = {(1,1):"Its a draw.",
          (2,2):"Its a draw.",
          (3,3):"Its a draw."}




def showMenu(): # Using dictionary for the menu
    selection = {'1': 'All computer generated',
                 '2': 'Quit'}
    print
    print
    print "Welcome to Rock, Paper, Scissors"
    print "================================"
    print
    print " \t\t\t\tInstructions\t\t\t\t\t\n The aim of this game is to play rock paper scissors. The computer is to \
            simulate the whole game by producing the results for each game along with a statement declaring who has won the match."


    print
    print "Enter your selection"
    print
    print "  1. ", selection['1'] 
    print
    print
    print "  2. ", selection['2']
    print

    # Now use try ..except to handle input for menu
    # for both KeyError and NameError and
    # call game choice functions

    while 1:
        prompt = "Your Choice: "
        choice = string.upper(raw_input(prompt))
        try:
            selection[choice]
        except KeyError:
            print "'%s' is not a valid option. Try again." % choice
            print
        if choice == '1':
            autoPlay()
        elif choice == '2':
            return

def autoPlay(): # re-use of ass2A
    print "This is computer generated auto picks!"
    print

# Here is the code so far
# for players A and B:
    while Ascore < 10 and Bscore < 10:
        x = 0
        y = 0
        print "hello"

        x = random.randrange(1,4)
        y = random.randrange(1,4)
        turnA = table[x]
        turnB = table[y]
        turnTuple = (x,y)

    print "player A chose:",turnA
    print "player B chose:",turnB
    print
def whoWins():  
    if turnTuple in Awins:
        print Awins[turnTuple]
        Ascore = Ascore + 1
    elif turnTuple in Bwins:
        print Bwins[turnTuple]
        Bscore = Bscore + 1
    elif turnTuple in Cdraws:
        Dscore = Dscore + 1
        print Cdraws[turnTuple]

#TESTING 1 2 3
def summary():
    print
    print "A scored: ", Ascore
    print "B scored: ", Bscore
    print "Draws: ", Dscore

def main():

    showMenu()
    whoWins()
    summary()

if __name__ == '__main__':
    main()

Edited by mike_2000_17: Fixed formatting

1
Contributor
1
Reply
2
Views
8 Years
Discussion Span
Last Post by pazoo
0

sory i forgot to use code tage on the provious post. cheers joel

import random
import string
Ascore = 0
Bscore = 0
Dscore = 0
table = {1:"Rock", 2:"Paper",3:"Scissors"}

turnTuple = ()

Awins = {(2,1):"Paper beats rock - Player A wins",
         (1,3):"Rock beats scissors - Player A wins",
         (3,2):"Scissors beat paper - Player A wins."}

Bwins = {(1,2):"Paper beats rock - Player B wins",
         (3,1):"Rock beats scissors - Player B wins",
         (2,3):"Scissors beat paper - Player B wins."}

Cdraws = {(1,1):"Its a draw.",
          (2,2):"Its a draw.",
          (3,3):"Its a draw."}


    
    
def showMenu(): # Using dictionary for the menu
    selection = {'1': 'All computer generated',
                 '2': 'Quit'}
    print
    print
    print "Welcome to Rock, Paper, Scissors"
    print "================================"
    print
    print " \t\t\t\tInstructions\t\t\t\t\t\n The aim of this game is to play rock paper scissors. The computer is to \
            simulate the whole game by producing the results for each game along with a statement declaring who has won the match."


    print
    print "Enter your selection"
    print
    print "  1. ", selection['1'] 
    print
    print
    print "  2. ", selection['2']
    print
    
    # Now use try ..except to handle input for menu
    # for both KeyError and NameError and
    # call game choice functions
    
    while 1:
        prompt = "Your Choice: "
        choice = string.upper(raw_input(prompt))
        try:
            selection[choice]
        except KeyError:
            print "'%s' is not a valid option. Try again." % choice
            print
        if choice == '1':
            autoPlay()
        elif choice == '2':
            return

def autoPlay(): # re-use of ass2A
    print "This is computer generated auto picks!"
    print

# Here is the code so far
# for players A and B:
    while Ascore < 10 and Bscore < 10:
        x = 0
        y = 0
        print "hello"
    
        x = random.randrange(1,4)
        y = random.randrange(1,4)
        turnA = table[x]
        turnB = table[y]
        turnTuple = (x,y)
            
    print "player A chose:",turnA
    print "player B chose:",turnB
    print
def whoWins():  
    if turnTuple in Awins:
        print Awins[turnTuple]
        Ascore = Ascore + 1
    elif turnTuple in Bwins:
        print Bwins[turnTuple]
        Bscore = Bscore + 1
    elif turnTuple in Cdraws:
        Dscore = Dscore + 1
        print Cdraws[turnTuple]
  
#TESTING 1 2 3
def summary():
    print
    print "A scored: ", Ascore
    print "B scored: ", Bscore
    print "Draws: ", Dscore

def main():
    
    showMenu()
    whoWins()
    summary()
    
if __name__ == '__main__':
    main()
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.