Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6721133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:17:37+00:00 2026-05-26T09:17:37+00:00

I am trying to write a Python program and I am having a hard

  • 0

I am trying to write a Python program and I am having a hard time getting my score. I have written it as a value returning function and every time I run the program it seems to skip the step where it retrieves the score unless I include an else statement which it will automatcially jump the the else statement.
I will attach the full code below.
Thank you very much for any help, I’m greatful!
This is also my first time posting in this forum I apologize if I screw something up.

#constants
Rock = 1
Paper = 2
Scissors = 3

#Define the main function
def main():

    #set control loop
    keep_going = 'Y'


    #set counter to zero
    computer_wins = 0
    player_wins = 0
    tie_score = 0

    #call display message
    display_message()

    while keep_going == 'y' or keep_going == 'Y':

        play_game()


        #prompt user to keep going
        keep_going = input('would you like to play again? (Y for Yes): ')

    print('The computer won', computer_wins, 'times')
    print('The player won', player_wins, 'times')
    print('There were', tie_score, 'tie scores')

def play_game():

    #get random input
    computer = get_random()

    #get the players input
    play = get_play()

    #validate input
    if play == '1' or play == '2' or play == '3':
        play == True
    else:
        play == False
        print('Error: Invalid Entry')
        play = input('Please enter 1 for Rock, 2 for Paper, or 3 for Scissors: ')

    if play == computer:
        print('Tie Score, Please try again')
        tie_score += 1

    else:
        get_score(computer, play)

    print('The computer chose:', computer)
    print('The player chose: ', play)


#define display message
def display_message():
    print('Welcome to Rock Paper Scissors, a game of chance to see who will')
    print('outsmart the other. This game is Man VS Computer.')
    print('The program will select a random integer and then ask you for an integer')
    print('1 for Rock 2 for paper or 3 for Scissors. The program will then tell')
    print('you who won the game.')
    print('GOOD LUCK!')
    print
    print

def get_random():
    import random

    #generate random int
    computer = random.randint(1, 3)
    return computer


def get_play():
    #prompt user to enter an integer 1, 2, or 3
    play = input('Select 1 for Rock, 2 for Paper, or 3 for Scissors: ')
    return play

def get_score(computer, play):

    if computer == 1 and play == 2:
        score = 'player wins'
        print('Paper covers Rock, Player Wins')
        #player wins
        player_wins += 1

    elif computer == 1 and play == 3:
        score = 'computer wins'
        print('Scissors cut Paper, Computer Wins')
        #computer wins
        computer_wins += 1


    elif computer == 2 and play == 1:
        score = 'computer wins'
        print('Paper covers Rock, Computer Wins')
        #computer wins
        computer_wins += 1

    elif computer == 2 and play == 3:
        score = 'player wins'
        print('Scissors cut Paper, Player Wins')
        #player wins
        player_wins += 1


    elif computer == 3 and play == 1:
        score = 'player wins'
        print('Rock smashes Scissors, Player Wins')
        #player wins
        player_wins += 1

    elif computer == 3 and play == 2:
        score = 'computer wins'
        print('Scissors cut Paper, Computer Wins')
        #computer wins
        computer_wins += 1


#call main function
main()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T09:17:37+00:00Added an answer on May 26, 2026 at 9:17 am

    There’s so much wrong with this, it’s hard to know where to start (but don’t get discouraged)…

    First of all, it looks like (mostly from your use of input vs. raw_input and your parens with your print statements) you’re using Python 3, which already is going to limit the amount of help you get. Most people are still using Python 2.6 or 2.7. But with that out of the way…

    The main remaining issues addressing your question are:

    First: you’re using strings for player input (e.g. ‘1’, ‘2’, ‘3’), and numbers for computer choice (e.g. 1, 2, 3). So you need to compare them as such. In other words, instead of:

    if computer == 1 and play == 2:
    

    You would need to say:

    if computer == 1 and play == '2':
    

    Second: you’re trying to reference one function’s variables in another one, and that won’t work. If you want your computer_wins, etc. variables to be global, you need to initialize them at the global scope, e.g. right after your “#constants” are declared and before you get into main. Then in any function that uses them, you must say e.g. global computer_wins to indicate they are global and not local.

    Once you get these issues addressed, it should work a bit better, but you’ll still need to do a lot of cleanup and keep working on it!

    Keep at it, and soon it will be natural for you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write a python program using Python 3 I have to
I am trying to write a python program that calculates a histogram, given a
I need some help calculating Pi. I am trying to write a python program
I'm trying to write a program in Python and I'm told to run an
I am trying to write my first real python function that does something real.
I'm currently trying to write a voicechat program in python. All tips/trick is welcome
I'm trying to write a secure transfer file program using Python and AES and
I'm trying to write a simple mail retrieval program in python. It seems the
Greetings, I'm trying to write a program in Python which would print a string
I am new to Python and I am trying to write a Server program.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.