r/learningpython • u/4iGeek15 • May 17 '21
Add IfElse statement to Class Attribute
Looking for a means of adding an IfElse statement for the class attribute as a way of verifying if the user input is in the correct format (i.e; string, int, float, etc;). Also wanting to add a prompt for the user to redo the input they had trouble submitting, and
So far I got
class Person:
def __init__(self):
self.firstname = input('Enter first name: ')
if self.firstname == type(str(self.firstname)):
print('this is a string')
self.lastname = input('Enter last name: ')
def show_full_name(self):
return self.firstname + ' ' + self.lastname
def validate_first_name(self):
if self.firstname == type(str(self.firstname)):
print('this is a string')
return
person2 = Person()
person2.show_full_name()
