Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am looking for help on ONLY part C in Python, please. Senate114.txt: Jeff Sessions,Alabama,R Richard Shelby,Alabama,R Lisa Murkowski,Alaska,R Dan Sullivan,Alaska,R John McCain,Arizona,R Jeff Flake,Arizona,R

I am looking for help on ONLY part C in Python, please.

image text in transcribed

Senate114.txt:

Jeff Sessions,Alabama,R Richard Shelby,Alabama,R Lisa Murkowski,Alaska,R Dan Sullivan,Alaska,R John McCain,Arizona,R Jeff Flake,Arizona,R Tom Cotton,Arkansas,R John Boozman,Arkansas,R Barbara Boxer,California,D Dianne Feinstein,California,D Cory Gardner,Colorado,R Michael Bennet,Colorado,D Richard Blumenthal,Connecticut,D Chris Murphy,Connecticut,D Chris Coons,Delaware,D Thomas Carper,Delaware,D Marco Rubio,Florida,R Bill Nelson,Florida,D Johnny Isakson,Georgia,R David Perdue,Georgia,R Brian Schatz,Hawaii,D Mazie Hirona,Hawaii,D Mike Crapo,Idaho,R Jim Risch,Idaho,R Mark Kirk,Illinois,R Richard Durbin,Illinois,D Dan Coats,Indiana,R Joe Donnelly,Indiana,D Joni Ernst,Iowa,R Chuck Grassley,Iowa,R Pat Roberts,Kansas,R Jerry Moran,Kansas,R Mitch McConnell,Kentucky,R Rand Paul,Kentucky,R David Vitter,Louisiana,R Bill Cassidy,Louisiana,R Susan Collins,Maine,R Angus King,Maine,I Benjamin Cardin,Maryland,D Barbara Mikulski,Maryland,D Elizabeth Warren,Massachusetts,D Edward Markey,Massachusetts,D Debbie Stebenow,Michigan,D Gary Peters,Michigan,D Amy Klobuchar,Minnesota,D Al Franken,Minnesota,D Thad Cochran,Mississippi,R Roger Wicker,Mississippi,R Claire McCaskill,Missouri,D Roy Blunt,Missouri,R John Walsh,Montana,D Steve Daines,Montana,R Deb Fischer,Nebraska,R Ben Sasse,Nebraska,R Dean Heller,Nevada,R Harry Reid,Nevada,D Kelly Ayotte,New Hampshire,R Jeanne Shaheen,New Hampshire,D Robert Menendez,New Jersey,D Cory Booker,New Jersey,D Martin Heinrich,New Mexico,D Tom Udall,New Mexico,D Kirsten Gillibrand,New York,D Charles Schumer,New York,D Thom Tillis,North Carolina,R Richard Burr,North Carolina,R John Hoeven,North Dakota,R Heidi Heitkamp,North Dakota,D Sherrod Brown,Ohio,D Rob Portman,Ohio,R James Inhofe,Oklahoma,R James Lankford,Oklahoma,R Jeff Merkley,Oregon,D Ron Wyden,Oregon,D Pat Toomey,Pennsylvania,R Robert Casey,Pennsylvania,D Sheldon Whitehouse,Rhode Island,D Jack Reed,Rhode Island,D Lindsey Graham,South Carolina,R Tim Scott,South Carolina,R John Thune,South Dakota,R Mike Rounds,South Dakota,R Lamar Alexander,Tennessee,R Bob Corker,Tennessee,R John Cornyn,Texas,R Ted Cruz,Texas,R Orrin Hatch,Utah,R Mike Lee,Utah,R Patrick Leahy,Vermont,D Bernard Sanders,Vermont,I Mark Warner,Virginia,D Tim Kaine,Virginia,D Maria Cantwell,Washington,D Patty Murray,Washington,D Joe Manchin,West Virginia,D Shelly Capito,West Virginia,R Ron Johnson,Wisconsin,R Tammy Baldwin,Wisconsin,D Michael Enzi,Wyoming,R John Barrasso,Wyoming,R

My code:

data = []

with open("Senate114.txt") as senate114:

states = []

for i in range(len(data)): for t in range(len(data)): if data[i][2] == data[t][2] and data[i][0]!=data[t][0]: states.append(data[i][1]) print(" States with senators of the same party affiliation:", len(list(set(states))))

Output:

States with senators of the same party affiliation: 50

My code is just counting the total number of states. How do I get the count of the states with reps of the same party affiliation?

4. U.S. Senate The file Senate113. txt contains the members of the 113th U.S. Senate that is, the Senate prior to the November 2014 election. Each record of the file consists of three fields name, state, and party affiliation. Some records in the file are as follows: Richard Shelby, Alabama, R Bernard Sanders, Vermont, I Kristen Gillibrand, New York,D The file RetiredSen. txt contains the records from the file Senate113.txt for senators who left the Senate after the November 2014 election due to retirement, defeat, death, or resignation. Some records in the file are as follows: John Rockefeller, West Virginia,D Tom Coburn, Oklahoma ,R Cari Levin, Michigan, D The file NewSen.txt contains records for the senators who were newly elected in November 2014 or who were appointed to fill the seats of senators who left after the November 2014 election. Some records in the file are as follows: Shelly Capito, West Virginia,R Steve Daines, Montana,R Gary Peters, Michigan, D (a) Write a program that uses the three files above to create the file Senate114.txt that contains records (each consisting of three fields) for the members of the 114th Senate where the members are ordered by state. Use this file in parts (b), (c), and (d). (b) Write a program that determines the number of senators of each party affiliation. See Fig. 5.49. (c) Write a program that determines the number of states whose two senators have the same party affiliation. (d) Write a program that asks the user to input a state, and then displays the two sena- tors from that state. See Fig. 5.50. Party Affiliations: Republicans: 54 Democrats: 44 Independents: 2 Enter the name of a state: Maryland Benjamin Cardin Barbara Mikulski FIGURE 5.60 FIGURE 6.49 Outcome of Programming Project 4(b). Outcome of Programming Project 4(d)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Climate And Environmental Database Systems

Authors: Michael Lautenschlager ,Manfred Reinke

1st Edition

1461368332, 978-1461368335

More Books

Students also viewed these Databases questions