我有一个小问题,在我的代码,我会很高兴,如果你能帮我解决它
我的问题是当词典在列表中时打印词典的值。 如果你能帮我解决代码中的这个问题,我会很高兴的
def func0():
print "Quiz Program"
print "----------------------------------------------"
print "This program stores quiz questions and allows you to take the quiz"
print "----------------------------------------------"
size = input("Enter number of questions: ")
i = 0
for i in xrange(size):
question = raw_input("Please enter a question, enter to exit: ")
question_dictionary = {"question" : question }
count = input("How many possible answers do you want this question to have: ")
answer_list = []
for j in xrange(count):
answer = raw_input("Please enter the next answer: ")
answer_list.append(answer)
print "------------------------------------------------"
for j in xrange(count):
print j + 1,"." ,answer_list[j]
print "------------------------------------------------"
question_dictionary["answers"] = answer_list
correct_answer = input("Please enter the value of the correct answer: ")
question_dictionary["correct_answer"] = correct_answer
new_list = []
new_list.append(question_dictionary)
print "------------------------------------------------"
true_answer = 0
for i in xrange(size):
print "question" ,i,".", # problem to print the question
print "------------------------------------------------"
print "Possible Answers: "
for j in xrange(count):
print j + 1,"." ,answer_list[j]
print "------------------------------------------------"
user_answer = input("Please select an answer: ")
if(user_answer == ): # problem to get the right answer
print "well done, you answered the question correctly!"
true_answer += 1
else:
print "sorry, you didn't get the correct answer."
print "------------------------------------------------"
print "Your final score was", true_answer," out of", size
def main():
func0()
if __name__ == "__main__":
main()
谢谢大家
试试这个。这只是一个补丁。不是真正的Python
相关问题 更多 >
编程相关推荐