Task In this task, we are going to write a program test8.py that implements a graphical...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Task In this task, we are going to write a program test8.py that implements a graphical quiz game. [ Question: All flamingos have 12 black flight feathers at the tips of each wing. You are provided with a text file containing quiz questions animals.txt (source) and a module readquiz.py with a function loadQuestions() able to read Yes/No questions from the questions file. The function returns a list of the form: ] Yes No Your answer was correct Score: 81/122 ['All dogs, cats and birds are colorblind.', False], ['Snake skin is covered in scales.', True], ['All tigers have stripes.', False], Each element of the list is a pair containing a trivia-style statement string and a True/False value that determines whether the statement is true or not. Step-by-step implementation: 1. Load questions from the file animals.txt using the module readquiz.py You will need at least three global variables: the list of questions, the number of times the player answered, and how many times they were correct: questions = readquiz. loadQuestions() total = 0 correct = 0 2. Create a Tkinter interface, arranging widgets as close as possible to the following layout (you may use additional Frame widgets to help arrange buttons and labels): Button "Yes" Question: Giraffes need less sleep than nearly every other animal. No Score: 0/0 Status Yes questionLabel = Label (root) questionLabel = Message(root, width=200) Label "Status of your previous answer" Label "Score" o When creating a label for the quiz question, you may use a Message widget instead of Label to get a multi-line text label. They are created the same way, but for Message you additionally specify its width: The difference between Label and Message: Status Label Question: If attacked by a shark it is recommended that you punch the shark in the nose. Yes No Question: Giraffes were once thought to be a cross between a camel and a leopard. Status Yes Label "Text of the question" (or Message widget) Button "No" No Score: 0/0 Score: 0/0 o The Status label in the bottom left is supposed to show if the player's previous answer was correct or incorrect o The Score label in the bottom right is supposed to show the ratio of correct answers (i.e. Score: correct/total, o The Status label in the bottom left is supposed to show if the player's previous answer was correct or incorrect o The Score label in the bottom right is supposed to show the ratio of correct answers (i.e. Score: correct/total, initially, it should show Score: 0/0). o The game should show a randomly sampled trivia statement from the list and allow the player to press a button "Yes" or "No" if they agree or disagree with the statement. (Note: Unlike with playing cards, here it is acceptable if the game happens to show a trivia statement that was seen before. The total number of trivia statements available is large enough so that such occurrences would be rare. In other words, you do not have to make sure that the game shows a different trivia statement each time.) o To make the game work, add ['command'] functions for the buttons. If a correct button is pressed, it should change the Status label to 'Your answer was correct' and its background to 'light green', otherwise change it to 'Your answer was incorrect' and its background to 'pink'. After that, it should load a new question, update globals correct and total, and update the Score label to show the updated ratio. After playing many rounds: Question: Are wild turkeys very good fliers? Yes No Your answer was correct Score: 1/1 Question: Is it true that goldfish only have a 3-second memory? Yes No Your answer was incorrect Score: 0/1 Question: Grizzly bears hibernate through the winter. Yes No Your answer was correct Score: 75/111 Question: A polar bear has white fur. Yes No Your answer was incorrect Score: 75/112 Your answer was incorrect Score: 75/112 There are many ways to make the buttons work correctly. We can give you one possible solution strategy: Define two functions for the buttons, describing what should happen when the player presses the correct button, and the incorrect one: def goodAnswer(): correct += 1 total + 1 ## Update Status and Score labels accordingly getNewQuestion () def badAnswer(): correct += 0 total += 1 ## Update Status and Score labels accordingly getNewQuestion() The function getNewQuestion() should sample a new question, update the question label, and then reassign the ['command' ] functions of the buttons. For example, if the question statement is False, then the Yes button should now execute badAnswer, and the No button should now execute goodAnswer. So in the proposed solution strategy, each time we update the question, we also update the behavior of the buttons. Task In this task, we are going to write a program test8.py that implements a graphical quiz game. [ Question: All flamingos have 12 black flight feathers at the tips of each wing. You are provided with a text file containing quiz questions animals.txt (source) and a module readquiz.py with a function loadQuestions() able to read Yes/No questions from the questions file. The function returns a list of the form: ] Yes No Your answer was correct Score: 81/122 ['All dogs, cats and birds are colorblind.', False], ['Snake skin is covered in scales.', True], ['All tigers have stripes.', False], Each element of the list is a pair containing a trivia-style statement string and a True/False value that determines whether the statement is true or not. Step-by-step implementation: 1. Load questions from the file animals.txt using the module readquiz.py You will need at least three global variables: the list of questions, the number of times the player answered, and how many times they were correct: questions = readquiz. loadQuestions() total = 0 correct = 0 2. Create a Tkinter interface, arranging widgets as close as possible to the following layout (you may use additional Frame widgets to help arrange buttons and labels): Button "Yes" Question: Giraffes need less sleep than nearly every other animal. No Score: 0/0 Status Yes questionLabel = Label (root) questionLabel = Message(root, width=200) Label "Status of your previous answer" Label "Score" o When creating a label for the quiz question, you may use a Message widget instead of Label to get a multi-line text label. They are created the same way, but for Message you additionally specify its width: The difference between Label and Message: Status Label Question: If attacked by a shark it is recommended that you punch the shark in the nose. Yes No Question: Giraffes were once thought to be a cross between a camel and a leopard. Status Yes Label "Text of the question" (or Message widget) Button "No" No Score: 0/0 Score: 0/0 o The Status label in the bottom left is supposed to show if the player's previous answer was correct or incorrect o The Score label in the bottom right is supposed to show the ratio of correct answers (i.e. Score: correct/total, o The Status label in the bottom left is supposed to show if the player's previous answer was correct or incorrect o The Score label in the bottom right is supposed to show the ratio of correct answers (i.e. Score: correct/total, initially, it should show Score: 0/0). o The game should show a randomly sampled trivia statement from the list and allow the player to press a button "Yes" or "No" if they agree or disagree with the statement. (Note: Unlike with playing cards, here it is acceptable if the game happens to show a trivia statement that was seen before. The total number of trivia statements available is large enough so that such occurrences would be rare. In other words, you do not have to make sure that the game shows a different trivia statement each time.) o To make the game work, add ['command'] functions for the buttons. If a correct button is pressed, it should change the Status label to 'Your answer was correct' and its background to 'light green', otherwise change it to 'Your answer was incorrect' and its background to 'pink'. After that, it should load a new question, update globals correct and total, and update the Score label to show the updated ratio. After playing many rounds: Question: Are wild turkeys very good fliers? Yes No Your answer was correct Score: 1/1 Question: Is it true that goldfish only have a 3-second memory? Yes No Your answer was incorrect Score: 0/1 Question: Grizzly bears hibernate through the winter. Yes No Your answer was correct Score: 75/111 Question: A polar bear has white fur. Yes No Your answer was incorrect Score: 75/112 Your answer was incorrect Score: 75/112 There are many ways to make the buttons work correctly. We can give you one possible solution strategy: Define two functions for the buttons, describing what should happen when the player presses the correct button, and the incorrect one: def goodAnswer(): correct += 1 total + 1 ## Update Status and Score labels accordingly getNewQuestion () def badAnswer(): correct += 0 total += 1 ## Update Status and Score labels accordingly getNewQuestion() The function getNewQuestion() should sample a new question, update the question label, and then reassign the ['command' ] functions of the buttons. For example, if the question statement is False, then the Yes button should now execute badAnswer, and the No button should now execute goodAnswer. So in the proposed solution strategy, each time we update the question, we also update the behavior of the buttons.
Expert Answer:
Related Book For
Introduction To Leadership Concepts And Practice
ISBN: 9781506330082
4th Edition
Authors: Peter G. Northouse
Posted Date:
Students also viewed these programming questions
-
a) Outline the Rostow Stages Theory of Economic Development. (10 Marks) b) Discuss the criticisms of linear models of Economic Development (5Marks)
-
Trade among nations has been growing faster than the total world GDP. The growth of U.S. exports and imports relative to the U.S. GDP parallels this global trend. Today, exports constitute more than...
-
You have learned a great deal about the Internet Protocol (IP). IP is a set of rules for how data is sent across networks and arrive at the intended destination. An IP address is a numeric identifier...
-
Assuming the use of a two -column (all-purpose) general journal, a purchases Journal, and a cash payments journal, indicate the journal In which each of the following transactions should be recorded:...
-
7. A three- process cycle of an ideal gas, for which c 1.064 and c 0.804 kJ/kg K is initiated by an isentropic compression 1-2 from 103.4 kPa, 27C to 608.1 kPa. A constant volume process 2-3 and a...
-
Below are the financial statements for two entertainment firms, Crosby Co. and Prairie Inc. for 2017 and 2018 a. How did Crosby Co.s profit margins change from 2017 to 2018? To what would you...
-
Caroline Company reports the following costs and expenses in May. InstructionsFrom the information, determine the total amount of:(a) Manufacturing overhead.(b) Product costs.(c) Periodcosts. Direct...
-
QUESTION 3 (20 MKS) a) Obtain the time-independent Schrodinger Wave equation from the time dependent equation. [10 mks] b) Solve the time-independent Schrodinger equation given that,(x) = Aekx [10...
-
Consolidation related simulation example: Millennium Capital Management, Inc., (MCM) acquired a 90% interest in NextGen, Inc. MCM's Financial Manager, Matthew Steven, has prepared a draft memo to the...
-
Describe the process of memory management in Python and discuss how the garbage collector functions.
-
Bern Zang is the chief investment officer of the Janson University Endowment Investment Office. The Janson University Endowment Fund (the Fund) is based in the United States and has current assets...
-
Which of the following set of derivative positions will most likely satisfy the ICs concern about the event-driven strategy involving AA and TT? A. Long out-of-the-money puts on AA shares and long...
-
Kloss Investments is an investment adviser whose clients are small institutional investors. Muskogh Charitable Foundation (the Foundation) is a client with $70 million of assets under management. The...
-
The risk tolerance of Maglavs pension plan can be best characterized as being: A. below average. B. average. C. above average. William Azarov is a portfolio manager for Westcome Investments, an asset...
-
Discuss the issues relating to Crees: i. goal quantification. ii. goal prioritization. McZhao continues the discussion with Cree in order to evaluate his degree of risk tolerance associated with each...
-
1- Use the Smithville_GL_Street Improvement Bond Debt Service Fund.docx to complete the steps in Chapter Six instructions General Ledger City of Smithville 4 - Street Improvement Bond Debt Service...
-
Smiths Family Fashions implemented a balanced scorecard performance measurement system several years ago. Smiths is a locally owned clothing retailer with fashions for men, women, teens, and...
-
What is your response to the word diversity? Do you think it is a significant problem in our society, or do you think it is overemphasized? Explain your thoughts on diversity.
-
Vanessa Mills was recently hired to work at a branch of Lakeshore Bank as a personal banker. The branch is very busy and has a large staff, including three on-site managers. As a new employee,...
-
Purpose 1. To identify your pathgoal styles of leadership 2. To examine how your use of each style relates to other styles of leadership Directions 1. For each of the statements below, circle the...
-
The emf of a copper-iron thermocouple caused by the Seebeck effect, with a cold junction at \(0{ }^{\circ} \mathrm{C}\), is given by \[\varepsilon=\alpha_{1} t+\frac{\alpha_{2}}{2}...
-
The emf of a copper-iron thermocouple with its cold junction at \(0{ }^{\circ} \mathrm{C}\) is given by \[\varepsilon=-13.403 t+0.0138 t^{2}+0.0001 t^{3} \quad \mu \mathrm{V}\] where \(t=\)...
-
A fluid consisting of a single component is contained in two containers at different temperatures. Show that the difference in pressure between the two containers is given by \[\frac{\mathrm{d}...
Study smarter with the SolutionInn App