Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- count = 0
- score = 0
- def check(your_choice, computer, score):
- if your_choice == 0:
- if computer == 1:
- print("You Lost!")
- elif computer == 2:
- print("You Won")
- score += 1
- else:
- print("Draw")
- if your_choice == 1:
- if computer == 2:
- print("You Lost!")
- elif computer == 0:
- print("You Won")
- score += 1
- else:
- print("Draw")
- if your_choice == 2:
- if computer == 0:
- print("You Lost!")
- elif computer == 1:
- print("You Won")
- score += 1
- else:
- print("Draw")
- return score
- def get_computer_choice(dict, i):
- for key, value in dict.iteritems():
- if value == i:
- return key
- def main(score, count):
- try:
- dict = {"rock": 0, "paper": 1, "scissors": 2}
- choice = raw_input('spelling is critical, choose rock paper or scissors:>')
- computer = random.randint(0, 2)
- if choice in dict:
- print("you chose %s and computer chose %s" %(choice, get_computer_choice(dict, computer)))
- your_choice = dict[choice]
- score = check(your_choice, computer, score)
- print("current score = %s" %score)
- else:
- print('please check you spelling')
- return score
- except:
- print("\r\nyour final score was %s out of %s games" %(score, count))
- if __name__ == "__main__":
- while True:
- try:
- count += 1
- score = main(score, count)
- except KeyboardInterrupt:
- print("your final score was %s" %score)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement