Question: 7 . 3 . 2 : Raising exceptions. Integers total _ grapes and grapes _ requested are read from input, representing the number of grapes
: Raising exceptions. Integers totalgrapes and grapesrequested are read from input, representing the number of grapes available and the number of grapes a customer wants to buy. In the try block:
Raise a ValueError exception with the message 'Number of grapes available must be positive' if totalgrapes is less than or equal to
Raise a ValueError exception with the message 'Number of grapes requested must be within range' if grapesrequested is less than or is greater than totalgrapes.
try:
totalgrapes intinput
grapesrequested intinput
# Your code goes here
grapesremaining totalgrapes grapesrequested
printfGrapes remaining: grapesremaining
except ValueError as excpt:
printfError: excpt
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
