0% found this document useful (0 votes)
9 views2 pages

Document 10c

Uploaded by

mohanraje2024
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views2 pages

Document 10c

Uploaded by

mohanraje2024
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Class MarksError(Exception):

“””Custom exception for invalid marks input.”””

Pass

Def check_marks_validity(marks):

Try:

# Convert marks to integer

Marks = int(marks)

# Check if marks are within the range of 0 to 100

If marks < 0:

Raise MarksError(“Marks cannot be negative.”)

Elif marks > 100:

Raise MarksError(“Marks cannot exceed 100.”)

# If marks are valid

Print(“Marks are within the valid range.”)

Except ValueError:

# Handles case when input is not an integer

Print(“Invalid input! Please enter a numeric value for marks.”)

Except MarksError as e:

# Handles custom marks-related errors

Print(f”Marks Error: {e}”)

Except Exception as e:
# Catches any other unexpected exceptions

Print(f”An unexpected error occurred: {e}”)

# Testing the function with different cases

Marks_input = input(“Enter the student’s marks: “)

Check_marks_validity(marks_input)

Output

Enter the student’s marks: 85

Marks are within the valid range.

You might also like