Consider a text file called elections.txt that contains the following lines: The file contains presidential-election res

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Consider a text file called elections.txt that contains the following lines: The file contains presidential-election res

Post by answerhappygod »

Consider a text file called elections.txt thatcontains the following lines:
The file contains presidential-election results from 1980 to thepresent. Each line contains five values separated by commas:
Given the file above, answer the following two questions:
(1 point) What is the output of the following code fragment?
Initially, you should determine the output by tracing throughthe code by hand. Once you have done so, you can check your answerby downloading the following files and running the program:
Make sure to put these files inyour ps4 folder. If your browser doesn’tallow you to specify where the file should be saved,try right-clicking on the link above andchoosing Save as... or Save linkas..., which should produce a dialog box that allows you tochoose the correct folder for the file.
(4 points) Modify the code fragment provided above so that itfinds all years in which the winner won a majority of the popularvote (i.e., more than 50 percent). For each such year, the revisedcode fragment should print the year, the winner’s last name, andhis percentage of the vote in parentheses, as shown below:
(Note: In the remaining years — 1992, 1996, 2000, and 2016 — athird-party candidate won enough of the vote to prevent anyone fromwinning a majority.) Your revised code should work for any filethat includes results that are formatted in the same way as theresults in elections.txt.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply