Question: [ 4 pt ] The getnrats function, assisted by the strs 2 rat function, prompts the user to enter a sequence of integer pairs, representing

[4pt] The getnrats function, assisted by the strs2rat function, prompts the user to enter a sequence of integer pairs, representing rational numbers, and returns the data as a list of tuples of integers. The functions validate user input in part through exception handling. What completes getnrats correctly?
def getnrats(): rationals =[] numstr = input("Enter an integer to divide (Q to quit): ") while numstr.upper()!="Q": denstr = input("Enter a positive integer to divide by: ") try: (num, den)= strs2rat(numstr, denstr) rationals.append((num, den)) print(str(error)) numstr = input("Enter an integer to divide (Q to quit): ") return rationals def strs2rat(numstr, denstr): num = int(numstr) # May raise exception den = int(denstr) # May raise exception if den ==0: raise ValueError("Denominator of rational cannot be 0!") elif den <0: (num, den)=(-num, -den) return (num, den)
Author: MK, Editor(s): JFM, DJ
Question 1Answer
a.
except ValueError:
cross out
b.
except ValueError as error:
cross out
c.
except IOError:
cross out
d.
except IOError as error:
cross out
e.
finally:

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 Programming Questions!