Question: (PYTHON)Write a function that prints out the ratio of registered democrat to republican voters for a particular voting district. The input parameters to the function

(PYTHON)Write a function that prints out the ratio of registered democrat to republican voters for a particular voting district.

The input parameters to the function should be two integers: number_of_democrats and number_of_republicans

For districts with all republican or all democrat voters, the function should print out All Republicans or All Democrats instead of a ratio Use simple (float) division to calculate the ratio, but use try and except.

In the "All Republicans" case, the ratio will be 0. In the "All Democrats" case, there will be a ZeroDivisionError. Your program should "catch" the error and print All Democrats". Under the EXCEPT statement, you can test to make sure that the user input is 0 or if there is some other error.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!