Oct-12-2019, 08:25 PM
(Oct-10-2019, 10:31 PM)ichabod801 Wrote: If you want the option to keep playing, you need another loop to put it all into (I think you put it around the end of game stuff, but it needs to go around everything). The format would be something like this:
while True: # do all of the set up stuff like initialize the scores. while game_not_over: # play the game if they_didnt_quit: # do the end of game stuff like determine and announce who won. play_again = input('Do you want to play again (y/n)? ') if play_again.lower() != 'y': break
Hi!,
Thank you for your reply. After several hours I haven't been able to figure this one out. It seems all I do is break the code in some way.
Here's what I've got now:
from random import randint # it's the same as "import random" which required to use # random.randint below to call the RNG (Random Number Generator) # instead, "randint(x,x) is used bellow. player_wins = 0 computer_wins = 0 wining_score = 3 game_active = True match = 1 win = ("You win!") + (" \U0001f600") nowin = ("Computer wins...") + (" \N{pile of poo}") while game_active == True: print(""" ██╗ ███████╗████████╗███████╗ ██████╗ ██╗ █████╗ ██╗ ██╗ ██║ ██╔════╝╚══██╔══╝██╔════╝ ██╔══██╗██║ ██╔══██╗╚██╗ ██╔╝ ██║ █████╗ ██║ ███████╗ ██████╔╝██║ ███████║ ╚████╔╝ ██║ ██╔══╝ ██║ ╚════██║ ██╔═══╝ ██║ ██╔══██║ ╚██╔╝ ███████╗███████╗ ██║ ███████║ ██║ ███████╗██║ ██║ ██║ ╚══════╝╚══════╝ ╚═╝ ╚══════╝ ╚═╝ ╚══════╝╚═╝ ╚═╝ ╚═╝ A game of Rock, Paper, Scissors created by Cesar Morales. """) while player_wins < wining_score and computer_wins < wining_score: print("") player = input("Make your choice: ").lower() # .lower() makes the player input lower case always. if player == "exit" or player == "quit" or player == "close" or player == "end": print("GAME OVER!") break if player == "rules" or player == "help": print(""" You will play against the computer. The best out of 3 will win.""") rand_num = randint(0, 2) if rand_num == 0: computer = "rock" elif rand_num == 1: computer = "paper" else: computer = "scissors" print(f"Computer chooses {computer}") if player == computer: print("It's a tie! \N{neutral face}") elif player == "rock": if computer == "scissors": player_wins += 1 print(win) elif computer == "paper": computer_wins += 1 print(nowin) elif player == "paper": if computer == "scissors": computer_wins += 1 print(nowin) elif computer == "rock": player_wins += 1 print(win) elif player == "scissors": if computer == "paper": player_wins += 1 print(win) elif computer == "rock": computer_wins += 1 print(nowin) else: if player != "r" or player != "p" or player != "s" or player != "exit" or player != "close" or player != "end" or player != "rules" or player != "help": print("INCORRECT INPUT!") if player_wins == 3 or computer_wins == 3: game_active = False while game_active == False: print("|=======================================|") print("|---GAME OVER---GAME OVER---GAME OVER---|") print("|=======================================|") print("\n") print(f"Player Score = {player_wins}") print(f"Computer Score = {computer_wins}") print("\n") if player_wins < computer_wins: print(""" ██████╗██████╗ ██╗ ██╗ ██╗ ██╗██╗███╗ ██╗███████╗ ██╔════╝██╔══██╗██║ ██║ ██║ ██║██║████╗ ██║██╔════╝ ██║ ██████╔╝██║ ██║ ██║ █╗ ██║██║██╔██╗ ██║███████╗ ██║ ██╔═══╝ ██║ ██║ ██║███╗██║██║██║╚██╗██║╚════██║ ╚██████╗██║ ╚██████╔╝ ╚███╔███╔╝██║██║ ╚████║███████║ ╚═════╝╚═╝ ╚═════╝ ╚══╝╚══╝ ╚═╝╚═╝ ╚═══╝╚══════╝ """) print(f"Player Score = {player_wins}") print(f"Computer Score = {computer_wins}") print(f"You have played {match} matches.") print("\n") print("\N{pile of poo} "*15) print(" ") print(" ") play_again = input("Want to play again? Y/N: ").lower() if play_again == "y": match += 1 game_active = True if play_again != "y": print("Ok. Goodbye!") break if player_wins == computer_wins: print(""" ████████╗██╗███████╗ ╚══██╔══╝██║██╔════╝ ██║ ██║█████╗ ██║ ██║██╔══╝ ██║ ██║███████╗ ╚═╝ ╚═╝╚══════╝ """) print(f"Player Score = {player_wins}") print(f"Computer Score = {computer_wins}") print(f"You have played {match} matches.") print("\n") print("It seems you quit the game while it was tied.") else: print(""" ██╗ ██╗ ██████╗ ██╗ ██╗ ██╗ ██╗██╗███╗ ██╗ ╚██╗ ██╔╝██╔═══██╗██║ ██║ ██║ ██║██║████╗ ██║ ╚████╔╝ ██║ ██║██║ ██║ ██║ █╗ ██║██║██╔██╗ ██║ ╚██╔╝ ██║ ██║██║ ██║ ██║███╗██║██║██║╚██╗██║ ██║ ╚██████╔╝╚██████╔╝ ╚███╔███╔╝██║██║ ╚████║ ╚═╝ ╚═════╝ ╚═════╝ ╚══╝╚══╝ ╚═╝╚═╝ ╚═══╝ """) print(f"Player Score = {player_wins}") print(f"Computer Score = {computer_wins}") print(f"You have played {match} matches.") print("\n") print("\N{grinning face with smiling eyes} "*14) print(" ") print(" ") play_again = input("Want to play again? Y/N: ").lower() if play_again == "y": match += 1 game_active = True if play_again != "y": print("Ok. Goodbye!") break