Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started