你能用什么而不是拉链?

时间:2016-02-17 05:01:43

标签: python zip asdf

Soooo,现在正在杀了我。应该早点问过很多,但我们去了。所以我认为我制作的拉链有问题,这让我很生气。如果有另一种方法可以做到这一点,请让我知道,但如果你教我如何使用拉链,那将是很棒的。此外,如果有人能指出我搞砸了的所有事情,那就太棒了。

    fun_string = """In ___0___, crazy ___1___ with ___2___, ate a meal called ___3___ on a grill""",
    horror_string = """In ___0___ owned by ___1___, many were killed by ___2___ because of huanted ___3___""",
    mystery_string = """The most mysterious place on Earth is ___0___, next     to ___1___'s house because of a ___2___ living in ___3___"""

    answers = [ ]
    blanks = ["___0___", "___1___", "___2___", "___3___"]
    def select_level():


        user_input = raw_input("""Type in a story you wish to play: """)

        while user_input not in ["Fun","Horror","Mystery"]:  
            user_input = raw_input("Invalid story. Please try again: ")
        if user_input == "Fun":
            quiz(fun_string, answers, blanks)
        if user_input == "Horror":
            quiz(horror_string, answers, blanks)
        if user_input == "Mystery":
            quiz(mystery_string, answers, blanks)  

    def zip(*iterables):
        # zip('ABCD', 'xy') --> Ax By
        iterables = map(iter, iterables)
        while iterables:
            yield tuple(map(next, iterables))

    def quiz(quiz_string, answers, blanks):
        print quiz_string
        for answer, question in zip(answers, blanks): 
            raw_input ("Type in a word: ")
            quiz_string = quiz_string.replace(blanks[1], answers)
            if blanks == None:
                print quiz_string




    print """Welcome to kis ReMadlibs!!!!"""
    print """Select a story you wish to particiate!!"""
    print """Fun, Horror, Mystery"""

    print select_level()

1 个答案:

答案 0 :(得分:2)

目前尚不清楚为什么你使用自己的zip()而不是Python的zip(),也不清楚为什么你认为你需要zip()。您可以通过简化代码来使该程序正常工作:

fun_string = """In ___0___, crazy ___1___ with ___2___, ate a meal called ___3___ on a grill"""
horror_string = """In ___0___ owned by ___1___, many were killed by ___2___ because of huanted ___3___"""
mystery_string = """The most mysterious place on Earth is ___0___, next to ___1___'s house because of a ___2___ living in ___3___"""

answers = []
blanks = ["___0___", "___1___", "___2___", "___3___"]

def select_level():

    user_input = raw_input("Type in a story you wish to play: ")

    while user_input not in ["Fun", "Horror", "Mystery"]:  
        user_input = raw_input("Invalid story. Please try again: ")

    if user_input == "Fun":
        quiz(fun_string, answers, blanks)
    elif user_input == "Horror":
        quiz(horror_string, answers, blanks)
    elif user_input == "Mystery":
        quiz(mystery_string, answers, blanks)  

def quiz(quiz_string, answers, blanks):
    print quiz_string

    for blank in blanks: 
        answer = raw_input("Type in a word: ")
        quiz_string = quiz_string.replace(blank, answer)
        answers.append(answer)

    print quiz_string

print """Welcome to kis ReMadlibs!!!!"""
print """Select a story you wish to particiate!!"""
print """Fun, Horror, Mystery"""

select_level()