Python Rock Paper Scissors function -


trying build basic rock paper scissors code, after adding function doesn't seem work, tell me, why?

print "1 stands paper, 2 stands rock, 3 stand scissors" signs = [1, 2, 3] gaming = 1 def game():     random import choice     pc = raw_input("pick sign, use numbers shown above ")     = int(pc)     cc = choice(signs)     if - cc == 0 : # 3 values         print "it's draw"     elif - cc == 1 : # 2 values         print "you lose"     elif  - cc == 2 : # 1 value         print "you win"     elif - cc == -1 : # 2 values         print "you win"     elif - cc == -2 : # 1 value         print "you lose"     gamin = raw_input("if want play again, press 1")     gaming = int(gamin) while gaming == 1 :     game 

from can tell, problem not calling game. add () call function:

while gaming == 1:     game() 

however, need restructure while-loop have game return gaming. also, there changes should make improve efficiency. rewrote program address this:

# import @ top of script random import choice print "1 stands paper, 2 stands rock, 3 stand scissors" # using tuple here faster using list signs = 1, 2, 3 def game():     = int(raw_input("pick sign, use numbers shown above "))     cc = choice(signs)     if - cc == 0:         print "it's draw"     elif - cc == 1:         print "you lose"     elif  - cc == 2:         print "you win"     elif - cc == -1:         print "you win"     elif - cc == -2:         print "you lose"     return int(raw_input("if want play again, press 1")) # have script loop until return value of game != 1 while game() == 1:     # pass do-nothing placeholder     pass 

notice got rid of few variables. in case, creating them didn't contribute positive script. removing them cleans code , improves efficiency.


Comments

Popular posts from this blog

iphone - Three second countdown in cocos2d -

hyperlink - how to do url routing in php -

c - Avoiding Extra Malloc in Linked List (node->next = NULL) -