Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Procedure
- You'll develop a script. Create a new file in IDLE and save it as prg1.py. Also download the flashcards.txt available with the course files on Canvas to test your program with. This file contains terms followed by their definitions, one pair per line. Each term is separated from its definition by a colon.
- You may collaborate with up to 2 other students on this lab if you wish, but you must have your collaborators approved by the instructor at least one week before the due date and agree that all students will receive the same grade. You may not share code with any students that are not in your group. Make sure your code is well documented, with a docstrings used at every appropriate opportunity.
- What to turn in
- Once you're finished, turn in the prg1.py file that you created.
- Instructions
- At the beginning of your script, read in all the values from the flashcards.txt file line by line (assume it is in your working directory -- don't hard-code a path). You'll need to split the line in to two separate values (the term and the definition). Trim off any leading or trailing whitespace from these strings. You can use any data structure you want, but realize that this assignment was designed with dictionaries in mind.
- Next, enter an indefinite loop in which you prompt the user with a random definition from the file. Read a line of input from the user and check to see if they correctly identified the matching term from the file (again, trim leading or trailing whitespace, and ignore case).
- If the user types "exit", break out of the loop and print out how many answers the user got correct and how many attempts they made.
- Sample Interactions
- Definition: a typing scheme which determines types are compatible as long as the requested methods or properties are present within the object
- What term does this define? goose
- Wrong!
- Correct answer: duck
- Definition: a sequence of statements and other blocks in a program
- What term does this define? block
- Correct!
- Definition: a language construct that is unnecessary but perhaps makes code shorter or easier to read
- What term does this define? not programming at all
- Wrong!
- Correct answer: syntactic sugar
- Definition: a datastructure which does not support order or multiplicity of elements and is mutable
- What term does this define? set
- Correct!
- Definition: collection of variable bindings available within a certain scope of a program
- What term does this define? quit
- Total Questions: 4
- Total Correct: 2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement