Knowee
Questions
Features
Study Tools

Write a program to accept marks from 1-100as input from user. If the user enters <40as an input or if user enters any negative number, or >100  user defined exception should begenerated.

Question

Write a program to accept marks from 1-100as input from user. If the user enters <40as an input or if user enters any negative number, or >100  user defined exception should begenerated.

🧐 Not the exact question you are looking for?Go ask a question

Solution

Here is a Python program that fulfills your requirements:

class InvalidMarksException(Exception):
    pass

marks = int(input("Enter marks between 1-100: "))

try:
    if marks < 40 or marks < 0 or marks > 100:
        raise InvalidMarksException("Invalid marks entered. Please enter marks between 1-100.")
    else:
        print("Marks entered successfully.")
except InvalidMarksException as e:
    print(e)

In this program, we first define a custom exception InvalidMarksException. Then we take marks as input from the user. If the marks are less than 40, less than 0, or greater than 100, we raise our custom exception. If the marks are within the valid range, we print a success message. If our custom exception is raised, we catch it in the except block and print the error message.

This problem has been solved

Similar Questions

e a Java program for the above with proper exception handling.Input-Output Form 1:

Write a program that repeatedly prompts a user for integer numbers until the user enters 'done'. Once 'done' is entered, print out the largest and smallest of the numbers. If the user enters anything other than a valid number catch it with a try/except and put out an appropriate message and ignore the number. Enter 7, 2, bob, 10, and 4 and match the output below.

Write a Java program that reads an unspecified number of scores anddetermines how many scores are above or equal to the average, and how many scoresare below the average. Enter a negative number to signify the end of the input. Assumethe maximum number of scores is 100.

Design a Student Mark List Generation System using Java.Define a class to store student's register number, name,attendance percentage and an integer array to store five subject marks.Define methods to read and print the student's details. Generate "InvalidMarksException: Marks must be within the range 0 to 30" , If the marks entered are less than 0 or greater than 30. Generate “InsufficientAttendanceException: Minimum Attendance Required is 75%” , if the attendance is less than 75%. Print the marklist only if there are no exceptions generated.Input FormatRegno – intName – StringAttendance – doubleMark1, Mark2, Mark3, Mark4, Mark5 – int Array elementsOutput FormatIf Exception is generated, display the message thrown by theException.Else, display the student details as shown below.Regno:Name:Attendance:Mark1:Mark2:Mark3:Mark4:Mark5:

Write a C program to compute the maximum marks and average marks of a class using sentinel controlled repetition (-1 as the sentinel value)?- If user enters negative marks then display INVALID INPUT and and read the marks again.- If number of students is 0, then display "NO DATA"- If number of students > 0, then display maximum marks and the average marks separated by space.-You can assume that marks are integers and average also you discard decimal value.

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.