dimanche 6 décembre 2020

I have a bug in my program that I cannot figure out

So, I just recently started coding and decided to make a rock paper scissors game; However, my program has a bug where if the user enters "rock" the correct code block doesn't run. Instead it runs an else statement that's only meant to run when the user enters, "no". I tried using a while loop instead of just if else statements but it didn't make a difference.

import random

q_1 = str(input("Hello, want to play Rock Paper Scissors?:"))

print()
# ^^adds an indent
rpc_list = ["rock", "paper", "scissors"]

comp = random.choice(rpc_list)
# ^^randomly selects r, p, or s

user = str(input("Great, select Rock Paper or Scissors:"))
if q_1 != "yes":
    if q_1 == comp:
        print("Oh No, a Tie!")
    elif q_1 == "rock":
        if comp == "paper":
            print("I Win!")
        else:
            print("You Win!")
    elif q_1 == "paper":
        if comp == "rock":
            print("You Win!")
        else:
            print("I Win!")
    else:
        if comp == "rock":
            print("I Win!")
        else:
            print("You Win!")
else:
    print("Ok :(")

Aucun commentaire:

Enregistrer un commentaire