Python Forum
help setting questions and answers in quiz game?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
help setting questions and answers in quiz game?
#3
Thank you so much @buran for all of your help - I can see what you mean about certain areas in my code being unecessary or useless ins ome areas, or not defined later on; and I greatly appreciate your cleaner version of code; it is easy to understand for a beginner like me, and looks much nicer.

I do have a question though, in your given code, on line 8, what does the i%2 do? I am trying to figure that out to myself but I can't come to a conclusion. Is it asking if each line is an even number?

Also, on a separate note, with two lists of questions and answers, I went ahead and made a function to print out each specific question, along with its given answer. My function definition(and following code) looks like this:

    def get_question(self):
        index = 0
        for item in self.questions:
            answer = self.answers[index]
            print(item)
            print(answer)
            index +=1
                               
                     
quiz = Game('movies_text.txt') # change this to your file name, incl. full path
#print(quiz.questions)
#print(quiz.answers)
print(quiz.get_question())
After i tested this, it showed me each question line, with each following answer - which is great because that is what I wanted. However, how do I run this function, and only get one question + answer pair at a time? Or, how do I set this up so that the user goes through each question when they want to move on, instead of displaying every question and answer pair? Thanks so much!
Reply


Messages In This Thread
RE: help setting questions and answers in quiz game? - by yoyoitsjess - May-10-2018, 02:55 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  quiz game - problem with loading statements from file lapiduch 2 1,151 Apr-20-2023, 06:13 PM
Last Post: deanhystad
Question Why do these codes give different answers? pooyan89 5 2,578 Dec-15-2020, 06:54 PM
Last Post: DeaD_EyE
  Basic Quiz/Game searching1 10 5,897 Nov-18-2018, 03:58 AM
Last Post: ichabod801
  Two Questions Regarding My Trivia Game martin28 1 2,445 Aug-19-2018, 02:07 PM
Last Post: martin28
  Quiz Game Help (ASAP Please!) beginnercoder04 2 3,253 Apr-15-2018, 04:13 AM
Last Post: beginnercoder04
  Just some second choice answers help please ajaY 6 5,227 Apr-07-2017, 08:25 PM
Last Post: micseydel

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020