Python - Raise Exception query

class Student:
def init(self,Name,Rollno):
self.__Name = Name
self.__Rollno = Rollno
def set_Name(self,x,f=False):
if f:
self.__Name = x
else:
raise ValueError(“Invalid Value in Name”)
#self.__Name = x
def get_Name(self):
print(“Your Name:” ,self.__Name)
return “”
def set_Rollno(self,y,g=False):
if g:
self.__Rollno = y
else:
raise ValueError(“Enter Valid Value in Roll No.”)
def get_Rollno(self):
print(“Your Roll No.:” ,self.__Rollno)
return “”
b1=str(input(“Enter Name :”))
b2=int(input(“Enter Roll No.”))
print(“*”*50)
b=Student(b1,b2)
b.set_Name(b1)
print(b.get_Name())
b.set_Rollno(b2)
print(b.get_Rollno())

Can You please explain ;

The Roll No. Exception is not working even if it is value Error only

Following is the error i’m getting
Enter Name :maya
Enter Roll No.may

ValueError Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_5028\3306363010.py in
21 return “”
22 b1=str(input(“Enter Name :”))
—> 23 b2=int(input(“Enter Roll No.”))
24 print(“*”*50)
25 b=Student(b1,b2)

ValueError: invalid literal for int() with base 10: ‘may’

2 Likes

@mick4mayank

You have taken the input in int than you are passing “may” as a string in roll no.