Created
August 26, 2017 17:37
-
-
Save mhnabi/dfec765830134ea9a9bca8bdd1e0e8bc 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
import sys | |
class Menu: | |
def __init__(self): | |
self.developers = [] | |
self.choices = { | |
"1": self.add_developer, | |
"2": self.add_skill, | |
"3": self.show_all, | |
"4": self.exit | |
} | |
def run(self): | |
while True: | |
print('-'*40) | |
print("1: Add developer\n" | |
"2: Add skill to a developer\n" | |
"3: Show all developers\n" | |
"4:Exit") | |
action = input("input your action you need: ") | |
if self.choices.get(action): | |
self.choices.get(action)() | |
print('-'*40) | |
def add_developer(self): | |
name = input("Enter name: ") | |
family = input("Enter family: ") | |
age = input("Enter age: ") | |
city = input("Enter city: ") | |
self.developers.append(Developer(name, family, age, city)) | |
def add_skill(self): | |
self.show_all() | |
id = int(input('Enter id: ')) | |
self.developers[id].add_skill() | |
def show_all(self): | |
print('{:3} | {:15} | {:15} | {:5} | {:10} | {:30}'.format("ID", "Name", "Family", "Age", "City", "Skills")) | |
for i, developer in enumerate(self.developers): | |
s = '{0:3} | {1:15}'.format(i, str(developer)) | |
print(s) | |
@staticmethod | |
def exit(): | |
sys.exit() | |
class Developer: | |
def __init__(self, name, family, age, city, skills=[]): | |
self.name = name | |
self.family = family | |
self.age = age | |
self.city = city | |
self.skills = skills | |
def add_skill(self): | |
skill = input('Enter skill: ') | |
self.skills.append(skill) | |
def __str__(self): | |
return '{:15} | {:15} | {:5} | {:10} | {:30}'.format(self.name, self.family, self.age, self.city, ", ".join(self.skills)) | |
Menu().run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment