vendredi 29 avril 2016

How do I complete this Python Tennis Kata?

I'm trying to write the Tennis Kata in python. I've written the code for a standard game, but somehow cannot figure out how to write the Deuce part. Could someone give me an algorithm or help me complete the program? It would be awesome if we can complete the program by just adding new functions and not removing anything. Thanks!

global player_score
player_score = 0
global comp_score
comp_score = 0


class Tennis:
    global player_score
    global comp_score    

    #def __init__(self):
        #self.player_score 
        #self.comp_score 

    def shot(self, player, comp):
        self.player = player
        self.comp = comp
        global player_score
        player_score+=player
        global comp_score
        comp_score+=comp

        #print player_score
        #print comp_score

    def score(self):
        global player_score
        global comp_score

        if player_score==40 and player_score>comp_score:
            print "Player Wins"

        elif comp_score==40 and comp_score>player_score:
            print "Computer Wins"

        elif player_score==40 and comp_score==40: #Deuce part

            pass







game = Tennis()
#game.shot(15,15)
game.shot(15,15)
game.shot(0,10)
game.shot(0,0)
#game.shot(10,0)
#game.shot(0,10)

game.score()


print player_score
print comp_score

Aucun commentaire:

Enregistrer un commentaire