[Python3] I made my first class! Feedback please.steemCreated with Sketch.

in #python7 years ago (edited)

Well, I just started a course on OOP with Python. Up until this point I had a lot of trouble grasping the concepts of, attributes and objects relating to classes but, I think I got it.  

Can any Python experts comment below and let me know what you think about my first useful class with methods.


# This is a test class made on 7/6/2017.
# Creates a class called User and sets, attributes for name and birth.
# Calculated how old user is and if their "oldenough" < 25 returns False.
# Alot of this is to just test things out
class User:
	#Birthday in yyyymmdd format
	def __init__(self, name, birth):
		self.name = name
		self.birth = birth
		self.byear = birth[0:4]
	#Checks year current year minus year born returns year born
	def yearsold(self):
		year = 2017
		age = year - int(self.byear)
		return age
	#returns False if younger than 25, and True for older than 25	
	def oldenough(self):
		if self.yearsold() < 25:
			return False
		else:
			return True
#Assigning an object called Ted to User with the required attributes
ted = User("Ted", "19941013")
rick = User("Rick", "18011230")
print(ted.name)
print(ted.byear)
print(ted.yearsold())
print(ted.oldenough())
print('.' * 25)
print(rick.name)
print(rick.byear)
print(rick.yearsold())
print(rick.oldenough())
#checks if the user is old enough 
#just wanted to test things out
if ted.oldenough() != True:
	print("Sorry {} you're only {} years old!".format(ted.name,ted.yearsold()))
else:
	print("Access Granted to: {}".format(ted.name))


Sort:  

gv3.jpg

New Followers get an upvote for free!!

Just follow us - we follow you back and your newest posting will receive an upvote for free! - @getvotes

Upvote!:) Good stuff, hope to see you more often here. Also, did you know that there are only 3 sets of letters on a keyboard which are in alphabetical order (f g h, j k l, and o p)!

I didn't know that. Now I do. Thanks!

Coin Marketplace

STEEM 0.24
TRX 0.11
JST 0.029
BTC 69425.69
ETH 3694.14
USDT 1.00
SBD 3.25