TEXT 19
Data Science Class Guest on 8th November 2022 10:07:06 AM
  1. from random import randint
  2.  
  3. rock = """
  4. ROCK
  5.     _______
  6. ---'   ____)
  7.       (_____)
  8.       (_____)
  9.       (____)
  10. ---.__(___)
  11. """
  12.  
  13. paper = """
  14. PAPER
  15.      _______
  16. ---'    ____)____
  17.            ______)
  18.           _______)
  19.          _______)
  20. ---.__________)
  21. """
  22.  
  23. scissor = """
  24. SCISSOR
  25.     _______
  26. ---'   ____)____
  27.           ______)
  28.        __________)
  29.       (____)
  30. ---.__(___)
  31. """
  32.  
  33. choice = ['rock','paper','scissors']
  34. ch = 'y'
  35. rounds = 0
  36.  
  37. def player_choice():
  38.     print (rock)
  39.     print (paper)
  40.     print (scissor)
  41.     plr_ch = input("\nPlease input complete word.\nEnter your choice Rock / Paper / Scissors: ")
  42.  
  43.     #player can input other char so check to ensure that cannot be broken
  44.     if plr_ch.lower() and plr_ch.lower() in ('rock','paper','scissors'):
  45.         return plr_ch.lower()
  46.     else:
  47.         print("\nWrong choice!! Retry !!")
  48.         player_choice()
  49.  
  50. def get_result(plr_ch):
  51.     comp_choice = choice[randint(0,2)]
  52.     print("\nComputer chose:",comp_choice,"\n")
  53.     if comp_choice=="rock":
  54.         print (rock)
  55.     elif comp_choice=="paper":
  56.         print (paper)
  57.     elif comp_choice=="scissors":
  58.         print (scissor)
  59.        
  60.  
  61.     if plr_ch == comp_choice:
  62.         result = "tie"
  63.         print('{} is same as {}! No score change!'.format(plr_ch.upper(), comp_choice.upper()))
  64.     elif comp_choice == 'scissors' and plr_ch == 'rock':
  65.         result = 'win'
  66.         print('ROCK crushes SCISSORS! You win! Score +1')
  67.     elif comp_choice == 'paper' and plr_ch == 'scissors':
  68.         result = 'win'
  69.         print('SCISSORS cut PAPER! You win! Score +1')
  70.     elif comp_choice == 'rock' and plr_ch == 'paper':
  71.         result = 'win'
  72.         print('PAPER covers ROCK! You win! Score +1')
  73.     else:
  74.         result = 'lose'
  75.         print('You lose! Score -1')
  76.     return result
  77.  
  78. def update_score(result):
  79.     global wins, loss, tie
  80.     if result == 'win':
  81.         wins += 1
  82.     elif result == 'lose':
  83.         loss += 1
  84.     else:
  85.         tie += 1
  86. def game(rounds):
  87.     tot_score = 0
  88.     global round_result
  89.     for i in range(0,rounds):
  90.         print("\nReady for Round", i+1)
  91.         pc = player_choice()
  92.         res = get_result(pc)
  93.         round_result.append(res)
  94.         update_score(res)
  95.         tot_score = wins - loss  # we can ignore tie as tie score is 0
  96.         print("\nAfter round",(i+1),"your score is: ",tot_score)
  97.  
  98.     return tot_score
  99.  
  100. def game_rounds(r = 0):
  101.     r = input("\nEnter how many rounds you want to play: ")
  102.     try:
  103.         global rounds
  104.         rounds = int(r)
  105.     except:
  106.         print("\nWrong Input! Enter a number!")
  107.         game_rounds()
  108.  
  109. def main():
  110.     global ch, round_result
  111.     print("\nWelcome to Rock, Paper, Scissors Game.\nRules are simple")
  112.     print('''\nWinning Rules are as follows:
  113.     Rock vs Paper -> Paper wins Rock Losses
  114.     Rock vs Scissors -> Rock wins Scissors Losses
  115.     Paper vs Scissors -> Scissors wins Paper Losses\n
  116.     For each win you get 1 point
  117.     If you lose -1 point
  118.     And if its a tie 0 point\n''')
  119.  
  120.  
  121.     game_rounds()
  122.     ts = game(rounds)
  123.     print("\nAfter",rounds,"rounds, your final score is: ",ts)
  124.     print("\nYou have {} wins, {} ties and {} losses!".format(wins,tie,loss))
  125.     print("\nRound wise result is",round_result)
  126.     ch = input("\nDo you want to continue? Enter y for yes any other char to exit: ")
  127.  
  128. while(ch == 'y' or ch == 'Y'):
  129.     wins = 0
  130.     loss = 0
  131.     tie = 0
  132.  
  133.     round_result = []
  134.     rounds
  135.     main()
  136. print("\nSee you Again!!")

Coding Base is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.