Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Big Data Fundamentals Concepts, Drivers & Techniques

Authors: Thomas Erl, Wajid Khattak, Paul Buhler

1st Edition

0134291204, 9780134291208

More Books

Students also viewed these Databases questions

Question

=+such as the dirigenti in Italy?

Answered: 1 week ago

Question

How do modern Dashboards differ from earlier implementations?

Answered: 1 week ago