443,767 Members | 2,114 Online
Need help? Post your question and get tips & solutions from a community of 443,767 IT Pros & Developers. It's quick & easy.

# Nim game for python

 P: 1 I need help with this game I'm trying to do for my class out of a python book. This is what is says in the book. A two-player version of the game Nim. In the game, players take turns removing from 1 to 4 sticks from a pile of 13. The player who picks up the last stick wins the game. Your program should validate the input from the players. This means that the program should continue to ask a player for the number of sticks he or she wishes to take as any of the following are true: - The number of sticks the player asks to take is greater than the number of sticks left. - The number of sticks the player asks to take is greater than 4, the maximum number that he or she is allowed to take. - The number of sticks the player asks to take is less than 1, the minimum number that he or she is allowed to take. This is what i have - print "Welcome to Nim." sticks = 13 picks = int(raw_input("How many sticks would you like to pick? ")) while (sticks != youwin): if picks == 1: print "you have picked ", picks,"stick there are", sticks - 1, \ "sticks left." if picks > 4: print "illegal guess" elif picks == 2: print "you have picked ", picks,"sticks, there are", sticks - 2, \ "sticks left." print raw_input("Pick another number.") elif picks == 3: print "you have picked ", picks,"sticks, there are", sticks - 3, \ "sticks left." print raw_input("Pick another number.") if sticks == 0: print "you win" raw_input("exit") Mar 15 '08 #1