Question: [ 4 pt ] The getnrats function, assisted by the strs 2 rat function, prompts the user to enter a sequence of integer pairs, representing
pt The getnrats function, assisted by the strsrat 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 inputEnter an integer to divide Q to quit: while numstr.upperQ: denstr inputEnter a positive integer to divide by: try: num den strsratnumstr denstr rationals.appendnum den printstrerror numstr inputEnter an integer to divide Q to quit: return rationals def strsratnumstr denstr: num intnumstr # May raise exception den intdenstr # May raise exception if den : raise ValueErrorDenominator of rational cannot be elif den : num dennum, den return num den
Author: MK Editors: JFM DJ
Question Answer
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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
