Question: [ HOMEWORK ] Problem # 1 . 1 The raise keyword is used to raise an exception. Write a Python code to raise Exception when
HOMEWORK Problem #
The raise keyword is used to raise an exception. Write a Python code to raise Exception when an age is younger than or older than Code
a simple raise statement for the conditional statement; Then, complete a code segment to do the follo
HOMEWORK Problem #
Recall Example above. Without changing the statement of the forloops, improve the code of Example to handle the exceptions
A sample output is as follows:
e
list index out of range
My Code :
# code :
import random
# Create a list of random integers based on your sample output, it looks like you have around elements
numbers random.randint for in range # List of random integers
print numbers
# Loop through the indices from to
for in range: # This includes an extra index which will cause an IndexError
try:
printfinumbersiwing:
Sample runs show below:Out of the bound
Enter your age:
Out of the bound
Your age is
My Code :
Code :
if age or age :whole code segment:
try:except Exception as e:
printe
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
