Skip to content

Instantly share code, notes, and snippets.

@prodeveloper
Created March 6, 2018 09:37
Show Gist options
  • Save prodeveloper/0a7978d69344b21f4942ab08a8bcfcdc to your computer and use it in GitHub Desktop.
Save prodeveloper/0a7978d69344b21f4942ab08a8bcfcdc to your computer and use it in GitHub Desktop.
Validation and working with files 6th March
class Student:
def __init__(self, names, email):
self.names = names
self.email = email
self.validateEmail()
self.validateName()
def validateEmail(self):
pass
def validateName(self):
if type(self.names) is not str:
raise ValueError("{} is not a valid name".format(self.email))
jane = Student("Jane","jane")
print(jane.email)
class Rectangle:
def __init__(self, length, width):
self.length = length
self.width = width
self.validateDimension()
def validateDimension(self):
try:
self.width = float(self.width)
self.length = float(self.length)
except ValueError:
raise ValueError("Dimensions can not be converted to integer")
def area(self):
return self.length * self.width
def perimeter(self):
return 2*(self.length + self.width)
invalid = Rectangle("6","5")
print(invalid.area())
class TaxPayer:
income = 0
name = "Jane Doe"
def __init__(self,name,income):
self.income = income
self.name = name
self.validateIncome()
self.validateName()
self.validateMinimum()
def validateIncome(self):
if self.income.isnumeric() == False:
raise ValueError("The income {} is not numeric".format(self.income))
def validateName(self):
if self.name.isnumeric():
raise ValueError("The name {} is not a string".format(self.name))
def validateMinimum(self):
if float(self.income) < 100001:
raise ValueError("Below minimum wage")
def calculate_tax(self):
return float(self.income) * 0.3
income = input("What is your income")
name = input("What is your name?")
employee = TaxPayer(name,income)
print(employee.calculate_tax())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment