Advertisement
Guest User

Untitled

a guest
Oct 30th, 2014
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.01 KB | None | 0 0
  1. from random import randint
  2.  
  3. #pc choice
  4.  
  5. def get_computer_hand():
  6.     r=randint(1,3)
  7.     if r == 1:
  8.         hand = "rock"
  9.     elif r == 2 :
  10.         hand = "paper"
  11.     elif r == 3 :
  12.         hand = "scissor"
  13.     return hand
  14.  
  15. # men el kseb
  16.  
  17. def whowin(you,comp):
  18.     if you == comp:
  19.         winner = "tie"
  20.     elif (comp == "rock" and you == "scissor") or (comp == "scissor" and you == "paper") or (comp == "paper" and you == "rock"):
  21.         winner = "comp"
  22.     else:
  23.         winner = "you"
  24.     return winner    
  25.  
  26.  
  27. # start
  28.  
  29. def play():
  30.     print "------welcome to my game------"
  31.     comp_wins = 0
  32.     you_wins = 0
  33.     tie_wins = 0
  34.     while True:
  35.         you = raw_input("Please choose rock or scissor or paper ")
  36.         you=you.lower()
  37.         if not you == "rock" or you == "paper" or you == "scissor" :
  38.             print" you choosed wrong answer"
  39.             continue
  40.         comp = get_computer_hand()
  41.         winner = whowin(you,comp)
  42.        
  43.  
  44.  
  45. play()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement