Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

My code says that there is invalid syntax on the number 0 in line 8 this is on python 3

+2 votes
asked Dec 24, 2022 by Rex (360 points)
edited Dec 25, 2022 by Rex
# Rock, Paper, Scissors Game
import random

# moves for player
moves = ["rock", "paper", "scissors"]

while True:
line 8    computer = moves[random 0,2]
    
    player = input("rock, paper or scissors? (or end the game)").lower()
    if player == "end the game":
        print ("The Game Has Ended.")
        break
    elif player == computer:
        print ("Tie!")
    elif player == "rock":
        if computer == "paper":
            print ("You Lose!")

2 Answers

+1 vote
answered Dec 24, 2022 by timomen (200 points)
0,2 is not a list index number. use round numbers. and i dont know if the "random" was intentional, but remove that if it isn't
commented Dec 25, 2022 by Rex (360 points)
what do you mean by round numbers?
commented Dec 25, 2022 by Rex (360 points)
Thank you so much by the way.
commented Dec 25, 2022 by Rex (360 points)
Also could you possibly give me the fixed code if not thank you for answering my question.
0 votes
answered Dec 25, 2022 by Peter Minarik (84,720 points)

Whit the following modification, your code now compiles and runs (but does not work correctly for all scenarios -- I'll leave you to fix these):

# Rock, Paper, Scissors Game
import random

# moves for player
moves = ["rock", "paper", "scissors"]

while True:
    computer = moves[random.randint(0, 2)]
    
    player = input("rock, paper or scissors? (or end the game)").lower()
    if player == "end the game":
        print ("The Game Has Ended.")
        break
    elif player == computer:
        print ("Tie!")
    elif player == "rock":
        if computer == "paper":
            print ("You Lose!")

Good luck!

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...