0

In my code for a maths quiz when i type N when it comes up with play again it plays again when it shouldnt. Here is my code:

def play_again():
    again= input("would you like to play again? y for yes and n for no")
    while again not in ['Y','y','N','n']:
        again = input("please enter 'Y' or 'N'")

    if again== 'y' or 'Y':
        do_the_quiz()
    else:
        print("cheers lad thanks for playing")
        exit()

can you spot something wrong in it that makes N or n play again when it shouldnt.

syntonym
  • 7,134
  • 2
  • 32
  • 45

2 Answers2

0

I think your if condition is wrong. It can either be:

if again=='y' or again=='Y':

or

if again in ['Y', 'y']:
Pynchia
  • 10,996
  • 5
  • 34
  • 43
0

if again== 'y' or 'Y': does not do what you think it does. or is a boolean operator, so the following is the same: if (again == 'y') or ('Y'). Because chars are alwayse treated as True in a boolean context your if branch will alwayse execute.

syntonym
  • 7,134
  • 2
  • 32
  • 45