Last active
April 23, 2018 09:37
-
-
Save KonradIT/aa6f534171fa32e390e4c6af7b2a08a2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print("TASK 2.3") | |
class Toy: | |
def __init__(self, name, ID, price, MinAge): | |
self.__name=name | |
self.__ID=ID | |
self.__price=price | |
self.__Minage=MinAge | |
def get(self, choice): | |
print(eval("self._Toy__"+choice)) | |
def set(self, choice, param): | |
if isinstance(param, int): | |
if choice=="Minage": | |
while param < 0 or param > 18: | |
param = int(input("Wrong. Age between 0 and 18 only; ")) | |
exec("self._Toy__%s = %d" % (choice,param)) | |
else: | |
exec("self._Toy__%s = %s" % (choice,param)) | |
t = Toy("he","TOY6",88,6) | |
print("Toy price:", end=" ") | |
t.get("price") | |
t.set("price",77) | |
print("Toy price:", end=" ") | |
t.get("price") | |
t.set("price","22") | |
print("Toy price:", end=" ") | |
t.get("price") | |
print("Toy minage",end=" ") | |
t.get("Minage") | |
print("Toy minage") | |
t.set("Minage", 69) | |
print("Toy minage",end=" ") | |
t.get("Minage") | |
print("============") | |
print("TASK 2.4") | |
#ComputerGame() CLASS: | |
class ComputerGame(Toy): | |
def __init__(self, name, id, price, minage, category, console): | |
Toy.__init__(self, name, id, price, minage) | |
self.__category=category | |
self.__console=console | |
def getConsole(self): | |
print(self.__console) | |
def setConsole(self, console_choice): | |
self.__console=console_choice | |
def getCategory(self): | |
print(self.__category) | |
def setCategory(self, category_choice): | |
self.__category=category_choice | |
fortnite=ComputerGame("fortnite","FN1",0,12,"MMO","xbox,pc,playstation") | |
print("ComputerGame Category:", end=" ") | |
fortnite.getCategory() | |
print("ComputerGame Console:", end=" ") | |
fortnite.getConsole() | |
print("ComputerGame name:", end=" ") | |
fortnite.get("name") | |
print("============") | |
#Vehicle() CLASS: | |
class Vehicle(Toy): | |
def __init__(self, name, id, price, minage, type, height, length, weight): | |
Toy.__init__(self, name, id, price, minage) | |
self.__type=type | |
self.__height=height | |
self.__length=length | |
self.__weight=weight | |
def getType(self): | |
print(self.__type) | |
def getHeight(self): | |
print(self.__height) | |
def getLength(self): | |
print(self.__length) | |
def getWeight(self): | |
print(self.__weight) | |
def setType(self, choice): | |
self.__type = choice | |
def setHeight(self, choice): | |
self.__height = choice | |
def setLength(self, choice): | |
self.__length= choice | |
def setWeight(self, choice): | |
self.__weight = choice | |
Red_Sports_Car=Vehicle("Red Sport Car","RSC13",15.00,6,"Car",3.3,12.1,0.08) | |
print("Vehicle Type:", end=" ") | |
Red_Sports_Car.getType() | |
print("============") | |
print("Task 2.7") | |
def GetAttrsById(classid): | |
classList= [Red_Sports_Car, fortnite, t] | |
from operator import attrgetter | |
sortedPeople=sorted(classList, key=attrgetter("_Toy__ID")) | |
for i in sortedPeople: | |
if i._Toy__ID == classid: | |
print("found") | |
#Work in progress | |
print("Name", i._Toy__name) | |
print("ID", i._Toy__ID) | |
print("Price", i._Toy__price) | |
print("Minimum age", i._Toy__Minage) | |
GetAttrsById("RSC13") | |
print("============") | |
print("Task 2.8") | |
def DiscountPrice(percentagedecrease): | |
classList= [Red_Sports_Car, fortnite, t] | |
from operator import attrgetter | |
sortedPeople=sorted(classList, key=attrgetter("_Toy__price")) | |
for i in sortedPeople: | |
temp=i._Toy__price | |
quickmafs=temp-(temp*percentagedecrease)/100 | |
i.set("price",quickmafs) | |
print("Before...", end=" : ") | |
print("Toy",end=" ") | |
t.get("price") | |
print("Game",end=" ") | |
fortnite.get("price") | |
print("Vehicle",end=" ") | |
Red_Sports_Car.get("price") | |
DiscountPrice(10) | |
print("Toy",end=" ") | |
t.get("price") | |
print("Game",end=" ") | |
fortnite.get("price") | |
print("Vehicle",end=" ") | |
Red_Sports_Car.get("price") | |
print("============") | |
print("TASK 2.10") | |
#Classes | |
fortnite=ComputerGame("fortnite","FN1",0,12,"MMO","xbox,pc,playstation") | |
pubg=ComputerGame("pubg","PUBG1",40,16,"Shooter","pc") | |
marioparty=ComputerGame("mario party","MP1",199,3,"Dancing","wii") | |
gta5=ComputerGame("GTA 5","GTA5",55,21,"MMO","pc") | |
monumentvalley=ComputerGame("monument valley","MV1",3,5,"mobile game","android,ios") | |
classList= [fortnite, pubg, marioparty, gta5, monumentvalley] | |
from operator import attrgetter | |
sortedPeople=sorted(classList, key=attrgetter("_Toy__price")) | |
print("\n") | |
for i in sortedPeople: | |
for j in i.__dict__: | |
print(j,end=": ") | |
print(i.__dict__.get(j)) | |
print("\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment