Advertisement
Guest User

Untitled

a guest
Aug 27th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. import sys
  2. import random
  3.  
  4. def compare(play,cplay):
  5. # test if player of computer win
  6. print "computer plays: ", cplay
  7. if play==cplay:
  8. return 'tie'
  9. if play=='rock' and cplay=='scissors':
  10. return 'player'
  11. if play=='rock' and cplay=='paper':
  12. return 'computer'
  13. if play=='scissors' and cplay=='paper':
  14. return 'player'
  15. if play=='scissors' and cplay=='rock':
  16. return 'computer'
  17. if play=='paper' and cplay=='rock':
  18. return 'player'
  19. if play=='paper' and cplay=='scissors':
  20. return 'computer'
  21.  
  22. def comp_play(num):
  23. if num%3==0:
  24. c_play='rock'
  25. elif num%2==0:
  26. c_play='paper'
  27. else:
  28. c_play='scissors'
  29. return c_play
  30.  
  31. def main():
  32.  
  33. print "\n\t\t\t ~ Rock Paper scissors ~ "
  34.  
  35.  
  36. #NOTE try a while(True) statement with an else: clause
  37. while(True): #run the loop of asking player for input
  38. prompt='>'
  39. print "Please enter your play (rock/paper/scissors) :: press q, or quit to quit"
  40. play=str(raw_input(prompt)).lower()
  41. if play=='q' or play=='quit':sys.exit(1)
  42. if play!='rock' and play!='scissors' and play!='paper':
  43. print "please enter a valid choice! "
  44. continue
  45.  
  46. print "Your play choice is '{}' ".format(play)
  47.  
  48. ##randomly generate choice decision for who wins
  49. # numbers 1-99 are inclusive, equal probability for picking multiple of 1,2, or 3
  50. num = random.randrange(1,100)
  51. counter_play = comp_play(num)
  52. winner=compare(play, counter_play)
  53.  
  54. if winner !='tie':
  55. print "\n the winner is: {} !!! ".format(winner.upper())
  56. continue
  57. else: # winner=='tie'
  58. print "\n It's a tie! Try again!"
  59. continue
  60.  
  61. #End of file
  62. if __name__=='__main__':
  63. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement