Python Forum

Full Version: Hi, my loop yes/no part doesn't work and I really need help
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey everyone, so I am in secondary school and have had to make a 'big program', and I have to include a yes/no in it to get the grade 8 (a*), whenever I type in no it just continues when it isn't supposed to, could you guys help me out please?

import random
import time
play = True
while play == True:
    print("Welcome to the roll the dice game!")

    player1 = input("What is your name, player1?")
    time.sleep(3)
    player2 = input("What is your name, player2?")

    print(player1,"and", player2 ," ", "Welcome to roll the dice!")

    promt = input(" Player1! You are chosen to roll the dice, press enter!")
    
    print("The dice are rolling!!! \n" * 4)
    time.sleep(3)
    choice = random.randint(1,6)
    if choice == 1:
            print(player1, " Your number is 1")
    elif choice == 2:
            print(player1, " Your number is 2")
    elif choice == 3:
            print(player1, " Your number is 3")
    elif choice == 4:
            print(player1, " Your number is 4")
    elif choice == 5:
            print(player1, " Your number is 5")
    elif choice == 6:
            print(player1, " Your number is 6")

    promt2 = input(" Player2 You are chosen to roll the dice, press enter!")

    print("The dice are rolling!!! \n" * 4)
    time.sleep(3)
    choice2 = random.randint(1,6)
    if choice2 == 1:
            print(player2, " Your number is 1")
    elif choice2 == 2:
            print(player2, " Your number is 2")
    elif choice2 == 3:
            print(player2, " Your number is 3")
    elif choice2 == 4:
            print(player2, " Your number is 4")
    elif choice2 == 5:
            print(player2, " Your number is 5")
    elif choice2 == 6:
            print(player2, " Your number is 6")

    if choice > choice2:
        print(player1, "Has won the game, bad luck" ," ", player2)
    if choice2 > choice:
        print(player2, "Has won the game, bad luck" ," ", player1)
        

    restart = input("Would you like to try again?")

    if restart == "yes" or "y":
        continue

    else:
        print("Good bye :)")
        play = False
        
     
This isn't homework by the way, I have just decided to do it so that I can get a better grade.
The statement:
if restart == "yes" or "y":
is equivalent to:
if restart == "yes" or "y" == "y":
which will always return true

it should be:
if restart == "yes" or restart == "y":