Python Forum
Help needed. Python Newbie!, it will be fun.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help needed. Python Newbie!, it will be fun.
#1
Smile 
Hi.

So I just started learning python as my first ever programming language. (YAYYY)

It's been 4 intense days (between kids and work) but I have created my first program. It's a rocks, papers, scissors game. Pretty simple.

The program runs fine until the part when the game ends when player_wins == 3 and/or computer_wins == 3.

Up to that point, what I want the program to do is to accept an input of "y/n" so I can continue playing if I want to without having to exit the game and start all over.

I am using a code editor with all the bells and whistles I could install to it called "Atom". Haven't been able to figure out how to run the code from within the editor tho. Every time I have to do it on terminal. (yes, im on a Mac)

If you guys want to mess around with the code and add a few functions (def) or anything else, feel free as I have not yet learned a lot about them and can't get them to work with my code. It breaks everything. I guess it's a matter of organization that I am doing completely wrong.

Sorry if the code is a mess, I am just learning as I go through and I find that practice is the best way to learn about coding. I get sleepy easily while reading long tutorials. Must be the age...

Also, if you guys know how to make this project an executable file that I can either run on Mac or PC, please let me know. =)

Anyways, thanks for your help and diligence. This is also my first post on your forum!

[quote]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}")



print("""
██╗     ███████╗████████╗███████╗    ██████╗ ██╗      █████╗ ██╗   ██╗
██║     ██╔════╝╚══██╔══╝██╔════╝    ██╔══██╗██║     ██╔══██╗╚██╗ ██╔╝
██║     █████╗     ██║   ███████╗    ██████╔╝██║     ███████║ ╚████╔╝
██║     ██╔══╝     ██║   ╚════██║    ██╔═══╝ ██║     ██╔══██║  ╚██╔╝
███████╗███████╗   ██║   ███████║    ██║     ███████╗██║  ██║   ██║
╚══════╝╚══════╝   ╚═╝   ╚══════╝    ╚═╝     ╚══════╝╚═╝  ╚═╝   ╚═╝
     A game of Rock, Paper, Scissors created by Cesar Morales. """)


while player_wins < wining_score and computer_wins < wining_score and game_active == True:

    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:
        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(" ")
        player = input("Want to play again? Y/N: ").lower()
        if player == "y":
            match += 1
            game_active = True

        if player == "n":
            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(" ")
        player = input("Want to play again? Y/N: ").lower()
        if player == "y":
            match += 1
            game_active == True

        if player == "n":
            print("Ok. Goodbye!")
            break
Reply
#2
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
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
(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
Reply
#4
You can have look at earlier thread about same subject Rock Paper Scissor GAME, especially about different ways to determine winner.
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python newbie laleebee 2 1,286 May-24-2022, 01:39 PM
Last Post: laleebee
  Python issue - Data science - Help is needed yovel 2 1,969 Jul-29-2021, 04:27 PM
Last Post: yovel
  Help needed for a python package keysson 1 2,174 Sep-02-2020, 03:37 AM
Last Post: Larz60+
  Absolutely new to python - basic advise needed mariolucas75 2 2,020 Jun-12-2020, 08:36 PM
Last Post: Yoriz
  Newbie on Python syntax rud0lp20 6 2,876 Apr-21-2020, 04:26 PM
Last Post: jefsummers
  python newbie marcush929 2 2,560 Jan-01-2020, 08:06 AM
Last Post: marcush929
  Python Linting (newbie) LieveHeer 2 2,578 Jan-24-2019, 05:36 PM
Last Post: LieveHeer
  help needed with python launcher fallenlight 3 3,344 Jan-19-2019, 01:06 PM
Last Post: snippsat
  Python newbie is asking Marcus_Gondwe 4 3,377 Apr-04-2018, 11:08 AM
Last Post: Marcus_Gondwe
  Newbie ? Python 3 Input() jlgrunr 1 2,429 Feb-17-2018, 10:26 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020