Python随机数拼图不起作用

时间:2015-02-21 22:24:30

标签: python

每当我说" no"到了"would you like to attempt the puzzle?",没有任何事情发生。我甚至只是在所有代码之后放了一个print ("test"),它没有执行测试。

puzzle1 = raw_input ("The cave has a small golden inscription on the door with a dial for imputting numbers. A puzzle! Would you like to attempt the puzzle?")
    #Puzzle 1
if path1 == "2":
    while breakhold2 == 0:
        if path1 == "2":
            if puzzle1.lower in ["Yes", "Ye", "Y", "y", "ye", "yes"]:
                print ("You press the button on the door. A small dial turns quickly and picks a random number between 1 and 50. Now you must guess the number being told to go 'higher' or 'lower'. You have only 5 tries to guess the random number.")

if path1 == "2":
    while breakhold2 == 0:
        if path1 == "2":
            if puzzle1.lower in ["Yes", "Ye", "Y", "y", "ye", "yes"]:
                from random import randrange
                puzzle1number = randrange(1,51)
                puzzle1number2 = raw_input ("What is the first guess? You have 5 tries left.")
                if int(puzzle1number2) == puzzle1number:
                    print ("You did it first try! Lucky you!")
                if int(puzzle1number2) > puzzle1number:
                    print ("Lower!")
                if int(puzzle1number2) < puzzle1number:
                    print ("Higher!")
                if int(puzzle1number2) == puzzle1number:
                    breakhold2 += 1
                    break
                else:
                    puzzle1number3 = raw_input ("What is the second guess? You have 4 tries left.")
                if int(puzzle1number3) == puzzle1number:
                    print ("You did it second try! Great guessing!")
                if int(puzzle1number3) < puzzle1number:
                    print ("Higher!")
                if int(puzzle1number3) > puzzle1number:
                    print ("Lower!")
                if int(puzzle1number2) == puzzle1number or int(puzzle1number3) == puzzle1number:
                    breakhold2 += 1
                    break
                else:
                    puzzle1number4 = raw_input ("What is the third guess? You have 3 tries left.")
                if int(puzzle1number4) == puzzle1number:
                    print ("You did it third try! Great guessing!")
                if int(puzzle1number4) < puzzle1number:
                    print ("Higher!")
                if int(puzzle1number4) > puzzle1number:
                    print ("Lower!")
                if int(puzzle1number4) == puzzle1number or int(puzzle1number4) == puzzle1number:
                    breakhold2 += 1
                    break
                else:
                    puzzle1number5 = raw_input ("What is the fourth guess? You have 2 tries left.")
                if int(puzzle1number5) == puzzle1number:
                    print ("You did it fourth try! That came kind of close.")
                if int(puzzle1number5) < puzzle1number:
                    print ("Higher!")
                if int(puzzle1number5) > puzzle1number:
                    print ("Lower!")
                if int(puzzle1number5) == puzzle1number or int(puzzle1number5) == puzzle1number:
                    breakhold2 += 1
                    break
                else:
                    puzzle1number6 = raw_input ("What is the fifth and final guess? This is your last try!")
                    if int(puzzle1number6) == puzzle1number:
                        print ("Finally! Got it on the last go!")
                    else:
                        print ("Blast! The small dial clicks and becomes unmovable. Whatever treasure was in there is now locked inside. I wonder why that was a lock?")
                        breakhold2 += 1
                        break

if path1 == "2":
    while breakhold2 == "0":
        if puzzle1.lower in ["No", "no", "n", "N"]:
            print ("You decide not to attempt the puzzle.")          
            breakhold2 += 1
            break

1 个答案:

答案 0 :(得分:1)

puzzle1.lower in ['yes', 'no', 'whatever', ...]永远是假的。

改为使用puzzle1.lower() in [....]

检查:

answer = 'Yes'

print(answer.lower)    
print(answer.lower in ['yes', 'y'])

对:

answer = 'Yes'

print(answer.lower())    
print(answer.lower() in ['yes', 'y'])