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.

i dont know why my code isnt working pls help this is an assignment and i cant find the solution in the passages

+3 votes
asked Dec 5, 2022 by Isabella (240 points)
edited Dec 6, 2022 by Isabella
from random import randint

random = randint(1, 3)
loop = True

while loop is True:

          print("Start of the game...")

if random == 1:
 player_choice = int(input("Type 1 for Rock, 2 for paper, 3 for scissors... : "))

if player_choice == 1:

                        print("You choose Rock!")

                        print("This round is a tie")

elif player_choice == 2:

                       print("You choose Paper!")

print("You won this round")

elif player_choice == 3:

                       print("You choose scissors!")

                       print("You lost this round")

elif random == 2:

         #2 is paper

         player_choice = input("Type 1 for Rock, 2 for paper, 3 for scissors... : ")

         if player_choice == 1:

                        print("You choose Rock!")

                       print("You lost this round")

        elif player_choice == 2:

                       print("You choose Paper!")

                       print("This round is a tie")

        elif player_choice == 3:

                       print("You choose scissors!")

                      print("You won this round")

elif random == 3:

         #3 is scissors

         player_choice = input("Type 1 for Rock, 2 for paper, 3 for Scissors... : ")

        if player_choice == 1:

                        print("You choose Rock!")

                      print("You won this round")

        elif player_choice == 2:

                       print("You choose Paper!")

                       print("You lost this round")

        elif player_choice == 3:

                       print("You choose Scissors!")

                       print("This round is a tie")

must be python 3

3 Answers

0 votes
answered Dec 6, 2022 by Bzzt Bzzt (140 points)

Fix your indentions, that's all it is.

from random import randint

random = randint(1, 3)
loop = True

while loop is True:

    print("Start of the game...")

if random == 1:
    player_choice: int = int(input("Type 1 for Rock, 2 for paper, 3 for scissors... : "))
    if player_choice == 1:

        print("You choose Rock!")

        print("This round is a tie")

    elif player_choice == 2:

        print("You choose Paper!")

        print("You won this round")

    elif player_choice == 3:

        print("You choose scissors!")
        
        print("You lost this round")

elif random == 2:

    #2 is paper

    player_choice = input("Type 1 for Rock, 2 for paper, 3 for scissors... : ")

    if player_choice == 1:

        print("You choose Rock!")

        print("You lost this round")

    elif player_choice == 2:

        print("You choose Paper!")

        print("This round is a tie")

    elif player_choice == 3:

        print("You choose scissors!")

        print("You won this round")

elif random == 3:

    #3 is scissors

    player_choice = input("Type 1 for Rock, 2 for paper, 3 for Scissors... : ")

    if player_choice == 1:

        print("You choose Rock!")

        print("You won this round")

    elif player_choice == 2:

        print("You choose Paper!")

        print("You lost this round")

    elif player_choice == 3:

        print("You choose Scissors!")

        print("This round is a tie")
0 votes
answered Dec 7, 2022 by Nathaniel Khoo (180 points)
put quotation marks '' between the numbers when you are processing an input.
0 votes
answered Dec 7, 2022 by Peter Minarik (84,720 points)

What is not working? Can you be more specific? Do you have compilation errors? Runtime errors? Or the code runs, but it doesn't do what you want it to do? What is that you want but works differently in the implementation?

If you get the indentations right your code runs OK (but it's an infinite loop and you don't have any nice way to exit).

from random import randint

random = randint(1, 3)
loop = True

while loop is True:
    print("Start of the game...")
    if random == 1:
        player_choice = int(input("Type 1 for Rock, 2 for paper, 3 for scissors... : "))
        if player_choice == 1:
            print("You choose Rock!")
            print("This round is a tie")
        elif player_choice == 2:
            print("You choose Paper!")
            print("You won this round")
        elif player_choice == 3:
            print("You choose scissors!")
            print("You lost this round")
    elif random == 2:
        #2 is paper
        player_choice = input("Type 1 for Rock, 2 for paper, 3 for scissors... : ")
        if player_choice == 1:
            print("You choose Rock!")
            print("You lost this round")
        elif player_choice == 2:
            print("You choose Paper!")
            print("This round is a tie")
        elif player_choice == 3:
            print("You choose scissors!")
            print("You won this round")
    elif random == 3:
        #3 is scissors
        player_choice = input("Type 1 for Rock, 2 for paper, 3 for Scissors... : ")
        if player_choice == 1:
            print("You choose Rock!")
            print("You won this round")
        elif player_choice == 2:
            print("You choose Paper!")
            print("You lost this round")
        elif player_choice == 3:
            print("You choose Scissors!")
            print("This round is a tie")
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.
...