Question: 7 . 3 . 2 : Raising exceptions. Integers total _ grapes and grapes _ requested are read from input, representing the number of grapes

7.3.2: Raising exceptions. Integers total_grapes and grapes_requested 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 total_grapes is less than or equal to 0.
Raise a ValueError exception with the message 'Number of grapes requested must be within range' if grapes_requested is less than 0 or is greater than total_grapes.
try:
total_grapes = int(input())
grapes_requested = int(input())
# Your code goes here
grapes_remaining = total_grapes - grapes_requested
print(f'Grapes remaining: {grapes_remaining}')
except ValueError as excpt:
print(f'Error: {excpt}')

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!