Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. import random
  2.  
  3.  
  4. def round_winner(choice):
  5. ai_chosen = str(random.randint(1, 3))
  6. print(f'AI chose {ai_chosen}')
  7.  
  8. if choice == '1' and ai_chosen == '2':
  9. return 'ai'
  10. elif choice == '2' and ai_chosen == '3':
  11. return 'ai'
  12. elif choice == '3' and ai_chosen == '1':
  13. return 'ai'
  14. elif choice == ai_chosen:
  15. return 'tie'
  16. else:
  17. return 'player'
  18.  
  19.  
  20. def display_round_winner(winner):
  21. if winner == 'tie':
  22. print('This round is tied!')
  23. else:
  24. print(f'The winner this round is the {winner.upper()}')
  25.  
  26. print(f'''
  27. Current points as follows:
  28. Player: {counter['player']}
  29. AI: {counter['ai']}
  30. Rounds Tied: {counter['tie']}
  31. ''')
  32.  
  33.  
  34. def score_checker():
  35. global game_ongoing
  36. for key, value in counter.items():
  37. if value == 2:
  38. print(f'{key.upper()} wins the game!')
  39. game_ongoing = False
  40.  
  41.  
  42. def initializer():
  43. global counter
  44. message = '''
  45. Please choose one of the following:
  46. 1: Rock
  47. 2: Paper
  48. 3: Scissors
  49. '''
  50.  
  51. print(message)
  52.  
  53. choice_of_obj = input('What will it be: ')
  54. if choice_of_obj in ['1', '2', '3']:
  55. winner = round_winner(choice_of_obj)
  56. counter[winner] += 1
  57. display_round_winner(winner)
  58. score_checker()
  59. else:
  60. print('Out of bounds')
  61.  
  62.  
  63. counter = {
  64. 'player': 0,
  65. 'ai': 0,
  66. 'tie': 0
  67. }
  68.  
  69. game_ongoing = True
  70.  
  71. while game_ongoing:
  72. initializer()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement