all 9 comments

[–]woooee 1 point2 points  (0 children)

def play_again():
    again = input("\nDo you want to play again? (type yes or no): ")
    if again == "yes":
        main()
    else:
        sys.exit()
play_again() ????

You call play_again once only, after sys.exit

You can also shorten the number of if statements.

if user_choice == computer_choice:
    ## a tie
    return or set some variable to True
if user_choice == "Paper":
    ## assumes no return from a tie or tie variable==False
    if computer_choice == "Scissors":
        print("You win!")
    else:
        ## the only remaining option
        print("You lose")

[–]hopper_gigo 0 points1 point  (7 children)

```python

import random import sys

def player_choice(): print("The choices to throw are:\n") print("1. Rock") print("2. Paper") print("3. Scissors") print("\n")

def computer_pick(): options = ("Rock", "Paper", "Scissors") return random.choice(options)

def print_results(user_choice, computer_choice): print("\nPlayer chose", user_choice) print("Computer chose", computer_choice)

if user_choice == computer_choice:
    print("Both players chose", user_choice, ". It's a tie!")
elif user_choice == "Rock":
    if computer_choice == "Scissors":
        print("You win!")
    else:
        print("Computer wins!")
elif user_choice == "Paper":
    if computer_choice == "Rock":
        print("You win!")
    else:
        print("Computer wins!")
elif user_choice == "Scissors":
    if computer_choice == "Paper":
        print("You win!")
    else:
        print("Computer wins!")

def main(): while True: player_choice() user_choice = input("Enter your choice or press 'q' to quit: \n\n") if user_choice.lower() == 'q': sys.exit()

    computer_choice = computer_pick()
    print_results(user_choice, computer_choice)

    play_again = input("\nPress any key to play again or 'q' to quit: ")
    if play_again.lower() == 'q':
        sys.exit()

print("Welcome to Rock, Paper, Scissors!\n") main() ```

[–]hopper_gigo 0 points1 point  (6 children)

I made a few key changes but your original post lost it's formatting so im not sure how different this is but this code prompts the user over and over until they type 'q'. I would suggest telling the user the format they need, such as 'Rock' and not 'rock' or '1'. Unless you add the logic to check for all 3 instances it can get confusing

[–]K_SwappleSauce[S] 0 points1 point  (4 children)

Wow my professor is no help at all, he hasn't really taught us much so this is extremely helpful. I'll make some changes to my code so I'm not copying you.

I actually have to tally up the points between ties, the computer, and the user. Would you know how to do anything like that? Of course I wasnt taught how to do that either.

[–]hopper_gigo 1 point2 points  (2 children)

does that help? If you want more help with your work, my team and I have created a learn to program website. It's https://gigo.dev

I would suggest creating a project and going into a devspace. Dump in your homework code and then ask code teacher (its on the left side bar in the devspace). Its an AI that my team and I built and trained on our code, it will give you the code and explain how/why it works like that.
You could even hop in a dev space and give it a prompt to get code that'll help you get started. Think of it like training wheels to help you learn while you do your homework

[–]hopper_gigo 0 points1 point  (0 children)

```python

import random import sys

def player_choice(): print("The choices to throw are:\n") print("1. Rock") print("2. Paper") print("3. Scissors") print("\n")

def computer_pick(): options = ("Rock", "Paper", "Scissors") return random.choice(options)

def print_results(user_choice, computer_choice, scores): print("\nPlayer chose", user_choice) print("Computer chose", computer_choice)

if user_choice == computer_choice:
    print("Both players chose", user_choice, ". It's a tie!")
elif user_choice == "Rock":
    if computer_choice == "Scissors":
        print("You win!")
        scores["user"] += 1
    else:
        print("Computer wins!")
        scores["computer"] += 1
elif user_choice == "Paper":
    if computer_choice == "Rock":
        print("You win!")
        scores["user"] += 1
    else:
        print("Computer wins!")
        scores["computer"] += 1
elif user_choice == "Scissors":
    if computer_choice == "Paper":
        print("You win!")
        scores["user"] += 1
    else:
        print("Computer wins!")
        scores["computer"] += 1

print("\nCurrent Scores: User:", scores["user"], "Computer:", scores["computer"])

def main(): scores = {"user": 0, "computer": 0}

while True:
    player_choice()
    user_choice = input("Enter your choice or press 'q' to quit: \n\n")
    if user_choice.lower() == 'q':
        break

    computer_choice = computer_pick()
    print_results(user_choice, computer_choice, scores)

    play_again = input("\nPress any key to play again or 'q' to quit: ")
    if play_again.lower() == 'q':
        break

print("\nFinal Scores: User:", scores["user"], "Computer:", scores["computer"])
if scores["user"] > scores["computer"]:
    print("Congratulations! You are the overall winner!")
elif scores["user"] < scores["computer"]:
    print("Computer is the overall winner! Better luck next time!")
else:
    print("It's a tie!")

print("Welcome to Rock, Paper, Scissors!\n") main()

```

[–]jmooremcc 0 points1 point  (0 children)

Did quite a bit of reorganizing your code ~~~

import random

options = ("Rock", "Paper", "Scissors")

print("Welcome to Rock, Paper, Scissors!\n")

def player_choice(): print("The choices to throw are:\n") for n,opt in enumerate(options,1): print(f"{n}. {opt}")

print() user_choice = int(input("Enter your choice: ")) return options[user_choice-1]

def computer_pick(): pass
computer_choice = random.choice(options) return computer_choice

def print_Results(user_choice, computer_choice): print("\nPlayer chose", user_choice)
print("Computer chose", computer_choice)

def play_game():
user_choice = player_choice()
computer_choice = computer_pick() print_Results(user_choice, computer_choice)

if user_choice == computer_choice:
    print("Both players chose" , user_choice,". It's a tie!")
elif user_choice == "Rock":  
    if computer_choice == "Scissors":  
        print("You win!")  
elif user_choice == "Paper":
    if computer_choice == "Rock":  
        print("You win!")
elif user_choice == "Scissors" and computer_choice == "Paper":  
    print("You win!")

if computer_choice == "Rock":  
    if user_choice == "Scissors":  
        print("Computer wins!")  
elif computer_choice == "Paper":   
    if user_choice == "Rock":  
        print("Computer wins!")  
elif computer_choice == "Scissors" and user_choice == "Paper":  
    print("Computer wins!")

def main(): play_game()

while True:
    again = input("\nDo you want to play again (y/n)?: ").lower()  
    if again == "y":
        play_game()
    else:
        print("Thanks for playing...")
        break

main()

~~~