0

I want the user to put their GPA with a limited range from 1 - 5 (classes & inheritance)

I have an assignemt for school to ask the user to input their GPA from a limited range 1 - 5 only. this is an assingment for (classes & inheritence) chapter. please any help is appreciated thanks this is the code i could make below: # This file contains classes definition: class Person: def __init__(self, Name, Age, Gender, SSN): self.__Name = Name self.__Age = Age self.__Gender = Gender self.__SSN = SSN # =======SETTERS======== def set_name(self, Name): self.__Name = Name def set_Age(self, Age): self.__Age = Age def set_Genden(self, Gender): self.__Gender = Gender def set_ssn(self, SSN): self.__SSN = SSN # =============Getters========= def get_Name(self): return self.__Name def get_Age(self): return self.__Age def get_Genden(self): return self.__Gender def get_SSN(self): return self.__SSN # the class named Student that is a subclass of the Person class class Student(Person): def __init(self, Name, Age, Gender, SSN, StudentID, GPA): Person.__init__(self, Name, Age, Gender, SSN) self.__StudentID = StudentID self.__GPA = GPA # ================setters======== def set_StudentID(self,StudentID): self.__StudentID = StudentID def set_GPA(self, GPA): self.__GPA = GPA # ============Getters===== def get_StudentID(self): return self.__StudentID def get_GPA(self): return self.__GPA # ===============str=============== def __str__(self): return 'Name: ' + Person.get_Name(self) + '\n Age: ' + str(Person.get_Age(self)) + \ '\n Gender: ' + str(Person.get_Genden(self)) + \ '\n SSN: ' + str(Person.get_SSN(self)) + '\n StudentID: ' + str(self.__StudentID) + \ '\n GPA: ' + str(self.__GPA)

29th Nov 2020, 3:11 PM
Nabilla
Nabilla - avatar
4 Réponses
0
How do you intend to instantiate an student object? You could test the value passed in the student class __init__() and set it to a default value if it's out of range or test the value before you instantiate the student object.
29th Nov 2020, 4:33 PM
rodwynnejones
rodwynnejones - avatar
+ 3
def set_Genden should be "set_Gender"... there are a couple other places this typo was made too
29th Nov 2020, 3:14 PM
Steven M
Steven M - avatar
0
I'm stuck in writing the code for the range entry: What I want is a way to force the user to enter numbers ranging from 1 - 5 and to display an error messege if anyother numbers are entered.
30th Nov 2020, 1:54 PM
Nabilla
Nabilla - avatar
0
Something like this should work. I am testing the function with in the for loop with a range simulating possible user input https://code.sololearn.com/cv4w0U7T7B14/?ref=app
30th Nov 2020, 2:16 PM
Steven M
Steven M - avatar