Ich bin neu in StackOverflow (1. Zeit Posting) und neu in der Programmierung mit Python. Derzeit in einem Kurs über Udacity eingeschrieben. Ich habe eine sehr schwere Zeit mit einem Projekt, das wir für diesen Kurs erhalten haben und beschlossen, hierher zu kommen, um zu sehen, ob jemand helfen könnte.Dieses Python-Quiz macht mich verrückt
Das Projekt soll ein Quiz mit 4 Leerzeichen erstellen, die vom Spieler korrekt beantwortet werden müssen. Es ist erforderlich, dass das Quiz mit der richtigen Antwort ausgedruckt wird, aber es fällt mir sehr schwer, das richtig auszudrucken.
Mein Code ist unten. Ich würde mich über jede Hilfe oder Ratschläge freuen, die ich dazu bekommen kann.
Danke!
easy_quiz = "If you ever get stuck, check out the __1__ for common
problems students face when attempting this project. If you need
additional help, you can schedule a 1:1 appointment with one of our
__2__ to get you un-stuck. This project should be __3__. If at any time
it becomes not fun, take a step back, deep breath, and ask for __4__!.
\n\n"
easy_answers = ["forums", "mentors", "fun", "help"]
medium_quiz = "Game must have 3 or more levels and each level contains 4 or more __1__ to fill in. Immediately after running the program, user is prompted to select a difficulty level from easy/__2__/hard. Once a level is selected, game displays a fill-in-the-blank and a prompt to fill in the first one. When player guesses __3__, new prompt shows with correct answer in the previous blank and a new prompt for the next blank. When player guesses __4__, they are prompted to try again. \n"
medium_answers = ["blanks", "medium", "correctly", "incorrectly"]
hard_quiz = "__1__ are used as __2__ to automate tasks which are likely to be repeated. Functions produce the appropriate output (typically with a __3__ statement) from the appropriate input (function parameters). Your code should take advantage of __4__ and variable names should reflect the values they store. \n"
hard_answers = ["Functions", "tools", "return", "variables"]
blanks = ["__1__", "__2__", "__3__", "__4__"]
difficulty = raw_input("\nChoose your difficuty level = easy, medium, or hard? ")
print ""
if difficulty == "easy":
quiz = easy_quiz
answers = easy_answers
print "You chose easy!\n\nYou will have 5 guesses to fill in each blank. Good Luck!!\n \n" + easy_quiz
elif difficulty == "medium":
quiz = medium_quiz
answers = medium_answers
print "You chose medium!\n\nYou will have 5 guesses to fill in each blank. Good Luck!!\n \n" + medium_quiz
elif difficulty == "hard":
quiz = hard_quiz
answers = hard_answers
print "You chose hard!\n\nYou will have 5 guesses to fill in each blank. Good Luck!!\n \n" + hard_quiz
def word_in_pos(word, parts_of_speech):
for pos in parts_of_speech:
if pos in word:
return pos
return None
def play_game(quiz, parts_of_speech):
replaced = []
i = 0
quiz = quiz.split()
for word in quiz:
replacement = word_in_pos(word, parts_of_speech)
if replacement != None:
user_input = raw_input("Type an answer for: " + replacement + " ")
word = word.replace(replacement, user_input)
replaced.append(word)
guesses = 0
while user_input != answers[i]:
guesses = guesses + 1
print "Incorrect, try again \n" + " ".join(replaced)
user_input = raw_input("Type an answer for: " + replacement + " ")
if guesses == 4:
return "\nGame Over! Better luck next time. \n"
print "Correct \n" + " ".join(replaced)
i = i + 1
word = word.replace(replacement, user_input)
replaced.append(word)
else:
replaced.append(word)
replaced = " ".join(replaced)
return replaced
print play_game(quiz, blanks)
Willkommen bei StackOverflow. Bitte lesen und befolgen Sie die Buchungsrichtlinien in der Hilfe. [zum Thema] (http://stackoverflow.com/help/on-topic) und [how to ask] (http://stackoverflow.com/help/how-to-ask) gilt hier. StackOverflow ist kein Design-, Codierungs-, Recherche- oder Lernprogramm. – Prune
Sie haben kein bestimmtes Problem beschrieben, daher können wir nicht viel tun (oder sollten), um Ihnen unter der Charta von Stack Overflow zu helfen. [Minimales, vollständiges, überprüfbares Beispiel] (http://stackoverflow.com/help/mcve) gilt hier. Wir können Ihnen nicht effektiv helfen, bis Sie Ihren MCVE-Code veröffentlicht und das Problem genau beschrieben haben. Wir sollten in der Lage sein, Ihren gebuchten Code in eine Textdatei einzufügen und das von Ihnen beschriebene Problem zu reproduzieren. – Prune
Hast du deine erwartete Forschung gemacht? Verschiedene Probleme mit dieser Aufgabe wurden auf SO und anderen unterstützenden Websites veröffentlicht. Wenn Sie ein neues Problem von allgemeinem Interesse haben, beschreiben und demonstrieren Sie es bitte für uns. – Prune