Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# main.py
import argparse
import prac1
import prac1 # prac1.py를 불러오겠다!
import prac2
import prac3

Expand Down
1 change: 1 addition & 0 deletions prac1.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
def say_hello():
print("Hello, World!")

# 지금 이 python script 파일을 실행했다면,
if __name__ == "__main__":
say_hello()
3 changes: 2 additions & 1 deletion prac4_yongdam.py → prac4_crystal.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ def read_file():
try:
with open(file_name, 'r') as f:
data = f.read()
print(data)
except FileNotFoundError:
print('There is no file has that file name')
print('There is not a file with that name.')

if __name__ == "__main__":
read_file()
29 changes: 25 additions & 4 deletions prac5.py → prac5_crystal.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,38 @@

class Zoo:
def __init__(self):
pass
self.animals = []

def add_animal(self, animal):
pass
self.animal = animal
if len(self.animals) != 0: # 리스트가 비어있지 않으면,
dup_ani = [(ani.name, ani.species) for ani in self.animals if ani.name == animal.name and ani.species == animal.species]
if len(dup_ani) != 0:
print(f'"{dup_ani[0][0]} the {dup_ani[0][1]}"은 이미 동물원에 있습니다. 다른 이름을 사용하거나, 다른 종으로 추가해주세요.')
else:
self.animals.append(animal)
else:
self.animals.append(animal) # 리스트에 값 추가


def show_animals(self):
pass
print("현재 동물원에는 다음 동물들이 있습니다 :")
for ani in self.animals:
print(f"- {ani.name} the {ani.species}")

def show_animals_by_species(self, species):
self.species = species
for ani in self.animals:
if ani.species == species:
print(f"- {ani.name} the {ani.species}")
else:
pass


class Animal:
def __init__(self, name, species):
pass
self.name = name
self.species = species

def main():
# 동물원을 선언하고 10마리의 동물들을 추가합니다.
Expand Down