0

I have been having trouble with my python code and have been asking around for help. I have heard mixed things about this website but i have no where else to turn so i was hoping someone on here could show me the light and see if they can find out what's wrong with my code (other then it being messy and inefficient). here it is

D=False

while D==False:

       input=raw_input("please type 1 for 10p, 2 for 20p, 3 for 50p, 4 for 1 pound")

       while input not in ['1', '2', '3', '4']:

        print "That is not a correct coin value"
        input = raw_input("input: ")
    else:
        if input=="1":
            m=m+10
        if input=="2":
            m=m+20
        if input=="3":
            m=m+50
        if input=="4":
            m=m+100

    print("your current credit in pennys is:")
    print(m)

    D2=raw_input("are you done")
    if D2=="yes" or "Yes":
         D=True
    else:
        D=False

I kind of mucked up the implantation of the code on here but you get the picture. It all works fine until you get to the bit asking you if you are done. For some reason it carries on even if you don't put yes. Can any nice coders out there tell me what's up with it

M. A. Kishawy
  • 5,001
  • 11
  • 47
  • 72

1 Answers1

0

This

if D2=="yes" or "Yes":

always evaluates to true, as it's essentially parsed like this:

if (D2=="yes") or "Yes":

You probably wanted:

if D2 == "yes" or D2 == "Yes":

Which is better written as:

if D2.lower() == "yes":

Or:

if D2 in ["yes", "Yes"]:
mipadi
  • 398,885
  • 90
  • 523
  • 479