May-08-2018, 04:39 AM
Hello! So I'm working on a quiz game as a project for my CS class, and what I'm trying to do is have my program read each line in a text file, and determine which lines are the questions, and which are the answers. The structure of the text file is: an all lower case question line, followed immediately in a new line with an all caps answer. I structured it that way so that I could easier set answers and questions based off of what is uppercase, and what is lowercase.
So far, this is what I have in my Movie and Game classes:
Im rather confused from here as to how I am supposed to actually get the question to read in a program, so that the user can actually try to test this quiz, and have the assigned answer follow? Would I just print off each corresponding index items in each question and answer lists (such as self._qs[1], and self._as[1])? This is all new to me, so I apologize if I butcher any terms, or don't use proper form! Also, the text file i'm reading from is called 'movies_text.txt'.
As a reference example, the structure in the text file of questions and answers is as follows:
what movie did tom hanks star in with hale berry?
CLOUD ATLAS
--
For my class project, we have to make some kind of game using GUI's, with Python - and Tkinter(if necessary). A lot of people make things like the snake game, or space invaders, etc. For my quiz game, i'm first trying to just get the quiz portion working, before I actually go in and set up the GUI. Hopefully that is enough information for context! Let me know if there's anything I can clarify!
So far, this is what I have in my Movie and Game classes:
class Movie: #sets up question and answer pair - in which a movie name is the proper answer def __init__(self, question, movie): self._question = question self._movie_answer = movie def get_question(self): #get the question return self._question def get_movie_answer(self): #get the answer to the question (movie name) return self._movie_answer class Game: def __init__(self): self._qs = [] self._as = [] with open(movies_text, 'r') as f: for line in f: index = 0 if line.isLower(): line = self._question.append(self._qs) line[index+1] = self._movie_answer.append(self._as) index +=1 else: line = self._movie_answer.append(self._as) line[index-1] = self._question.append(self._qs) index +=1Basically what i'm trying to do in the code above is have the program read each line, and if it starts and is all lowercase, then the program will know to set that to the question, and it also knows then that the following line will be the answer. Otherwise, the program is starting on a line that is all caps, and it knows that the previous line is the question.
Im rather confused from here as to how I am supposed to actually get the question to read in a program, so that the user can actually try to test this quiz, and have the assigned answer follow? Would I just print off each corresponding index items in each question and answer lists (such as self._qs[1], and self._as[1])? This is all new to me, so I apologize if I butcher any terms, or don't use proper form! Also, the text file i'm reading from is called 'movies_text.txt'.
As a reference example, the structure in the text file of questions and answers is as follows:
what movie did tom hanks star in with hale berry?
CLOUD ATLAS
--
For my class project, we have to make some kind of game using GUI's, with Python - and Tkinter(if necessary). A lot of people make things like the snake game, or space invaders, etc. For my quiz game, i'm first trying to just get the quiz portion working, before I actually go in and set up the GUI. Hopefully that is enough information for context! Let me know if there's anything I can clarify!