jeudi 19 octobre 2017

If block only running the code under 'if' even when the conditions say not to [duplicate]

This question already has an answer here:

Please excuse me if this is stupid, I've just started learning python for GCSE computer science.

So the issue I'm experiencing is a bit odd. Even when conditions are or aren't met, only the code under the if block is run.

while True:
rand = str(input("[•.•] Would you like me to generate a random range? Yes or no? "))
if rand == "yes" or "Yes":
    print("[•‿•] Very well, give me a second.")
    basenum = random.randrange(0, 90)
    baseinc = basenum + 10
    numpick = random.randrange(basenum, baseinc)
    time.sleep(1)
    print("[•‿•] All sorted! I'm thinking of a number between " + str(basenum) + " and " + str(baseinc) + ".")
    break
else rand == "no" or "No":
    while type(basenum) or type(baseinc) != integer:
        basenum = input("What would you like the lowest number I can pick from to be? ")
        if type(basenum) != integer:
            print("[-_-] Sorry " + name + ", don't think " + str(basenum) + " is a number I can work with.")
        elif type(basenum) == integer:
            print("[•ᗜ•] Oooeee, can do!")
        baseinc = input("What would you like the highest number I can pick from to be? ")
        if type(basenum) != integer:
            print("[-_-] Sorry " + name + ", I can't do " + str(basenum) + ".")
        elif type(basenum) == integer:
            print("[•ᗜ•] Will do!")
    numpick = random.randrange(basenum, baseinc)
    time.sleep(1)
    print("[•‿•] All sorted! I'm thinking of a number between your chosen numbers " + str(basenum) + " and " + str(baseinc) + ".")
    break
else:
    print("[-_-] I don't understand " + rand + ". Please give me a yes or no answer")

Even when the variable rand = "no" it will still run the code which it should run when rand = "yes". I cannot see any issue here, (bear in mind I started learning python 4 weeks ago), and nothing I try seems to work.

I'm running python 3.4.3

Aucun commentaire:

Enregistrer un commentaire