Menu

[Solved]Python Need Create Definition Load Filename Deck Takes Given Filename Opens Extracts Lines Q37081779

Part 1: Loading STR Questions fromn a File In this part we will be learning to load decks from a save file. Save files have a

Functions load filename, deck): This function will load cards from a file (in the format shown above) and put them in the p

Representing a Flashcard, a Deck of Flashcards, and Quiz Statistics Define the dictionaries formats you will use here, for ex

(Python only)

I need to create the definition load(filename, deck): that takesa given filename, opens it, extracts the lines. Puts it in adictionary with keys listed in the third photo then adds it to”deck” which is a list of dictionaries

Part 1: Loading STR Questions fromn a File In this part we will be learning to load decks from a save file. Save files have already been provided to you with this document (they are the files with the .deck extension) and in this section we will specifically be working with deck_str.deck. You can open these files with any text editor to see what they look like, you may need to right click the file and select “open with” in some operating systems Below is deck str.deck: 1;STR;What is the answer of the following expression? Surround strings with double quotes (like “this”). “3”+”3″; “33” 22;STR;What is the string answer of the following expression? Surround your answer with double quotes (like “this”). “a””b “+”c”+ ” d.”;”ab c d.” Note that there are actually only two lines in the file (shown in not-bold and bold above and numbered on the side), but that due to the space in this document they are wrapping around. The actual file does not do this if you open it in a program that doesn’t do line-wrapping (e.g·if you open it with your code editor) What are vou seeing. Each line represents ONE card, in its entirety and the different “parts” of the card are separated with semicolons (;). The following explains the parts 1. the card’s id – the number before the first semicolon (you may assume this is an integer) 2. the card’s type – always ‘STR’ for now, you may assume this is always valid 3. the question – you may assume that the question does not contain any semicolons 4. the answer – you may also assume that this does not contain any semicolons either tl;dr Decks have a special file format described above. You need to understand that format so you can load the questions into the pro Functions load filename, deck): This function will “load” cards from a file (in the format shown above) and put them in the provided deck of cards (an array of dictionaries). Things you’ll need: . You need to open, read in, and close the file. Each line of the file is one string which represents a card. Use your knowledge of file IO and/or string manipulation to break each line into its component parts. Take the component parts and make a card out of them. Add the card to the deck provided (this function returns None, you must manipulate the deck given). Hints/Tips: We promise the files we give you are (and will be) in the correct format for all tests. However, if you write your own, make sure you’re following the format carefully! Remember to strip off the whitespace if you use readlines)! . Go read the “allowed things” section for file IO and strings… make sure you know how each function mentioned works… there are some hints in what we’re allowing you to use For right now the only type of card you need to worry about is STR cards. tl: dr You’ll want to read this when you go to write the loadO function Representing a Flashcard, a Deck of Flashcards, and Quiz Statistics Define the dictionaries formats you will use here, for example 1. A flashcard will map various card information to specific values. There are three types of questions on your flashcards Questions where the answer is text (a string) Questions where the answer is a number (an integer for simplicity) Multiple-choice questions . We will refer to these as STR, NT, and MC questions in this document In the computer, you will represent each flashcard with the following dictionary structure (‘id’: int, ‘type str, ‘q’ str, ‘a’: …, ‘aux: So, the id field will be an integer, the type will be a string (specifically ‘STR’, ‘INT’, or ‘MC), and the question (q) will be a strinsg The answer (a) will be one of several possible types depending on the type of question: . For STR questions, the answer is (not surprisingly) a string . For INT questions, the answer is an integer . For MC questions, the answer is an integer (the choice number for the correct answer) The auxiliary (aux) field will be None for STR and INT questions and for MC questions it will contain a list of strings (the options you can choose for the question) Below is an example of a few flashcards: card! = {‘id’: 1, type ‘STR qWhat class are you in?’, a’: “CS112” “auxNone) Show transcribed image text Part 1: Loading STR Questions fromn a File In this part we will be learning to load decks from a save file. Save files have already been provided to you with this document (they are the files with the .deck extension) and in this section we will specifically be working with deck_str.deck. You can open these files with any text editor to see what they look like, you may need to right click the file and select “open with” in some operating systems Below is deck str.deck: 1;STR;What is the answer of the following expression? Surround strings with double quotes (like “this”). “3”+”3″; “33” 22;STR;What is the string answer of the following expression? Surround your answer with double quotes (like “this”). “a””b “+”c”+ ” d.”;”ab c d.” Note that there are actually only two lines in the file (shown in not-bold and bold above and numbered on the side), but that due to the space in this document they are wrapping around. The actual file does not do this if you open it in a program that doesn’t do line-wrapping (e.g·if you open it with your code editor) What are vou seeing. Each line represents ONE card, in its entirety and the different “parts” of the card are separated with semicolons (;). The following explains the parts 1. the card’s id – the number before the first semicolon (you may assume this is an integer) 2. the card’s type – always ‘STR’ for now, you may assume this is always valid 3. the question – you may assume that the question does not contain any semicolons 4. the answer – you may also assume that this does not contain any semicolons either tl;dr Decks have a special file format described above. You need to understand that format so you can load the questions into the pro
Functions load filename, deck): This function will “load” cards from a file (in the format shown above) and put them in the provided deck of cards (an array of dictionaries). Things you’ll need: . You need to open, read in, and close the file. Each line of the file is one string which represents a card. Use your knowledge of file IO and/or string manipulation to break each line into its component parts. Take the component parts and make a card out of them. Add the card to the deck provided (this function returns None, you must manipulate the deck given). Hints/Tips: We promise the files we give you are (and will be) in the correct format for all tests. However, if you write your own, make sure you’re following the format carefully! Remember to strip off the whitespace if you use readlines)! . Go read the “allowed things” section for file IO and strings… make sure you know how each function mentioned works… there are some hints in what we’re allowing you to use For right now the only type of card you need to worry about is STR cards. tl: dr You’ll want to read this when you go to write the loadO function
Representing a Flashcard, a Deck of Flashcards, and Quiz Statistics Define the dictionaries formats you will use here, for example 1. A flashcard will map various card information to specific values. There are three types of questions on your flashcards Questions where the answer is text (a string) Questions where the answer is a number (an integer for simplicity) Multiple-choice questions . We will refer to these as STR, NT, and MC questions in this document In the computer, you will represent each flashcard with the following dictionary structure (‘id’: int, ‘type str, ‘q’ str, ‘a’: …, ‘aux: So, the id field will be an integer, the type will be a string (specifically ‘STR’, ‘INT’, or ‘MC), and the question (q) will be a strinsg The answer (a) will be one of several possible types depending on the type of question: . For STR questions, the answer is (not surprisingly) a string . For INT questions, the answer is an integer . For MC questions, the answer is an integer (the choice number for the correct answer) The auxiliary (aux) field will be None for STR and INT questions and for MC questions it will contain a list of strings (the options you can choose for the question) Below is an example of a few flashcards: card! = {‘id’: 1, type ‘STR qWhat class are you in?’, a’: “CS112” “auxNone)

Expert Answer


Answer to (Python only) I need to create the definition load(filename, deck): that takes a given filename, opens it, extracts the … . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *