본문 바로가기

Python_Matter/Solve

Python Learn the basics Quiz 36

반응형

Q>

메뉴

수행 명령어 

r 승객이름 항공편

항공 예약

f 항공편

항공편에 예약된 승객 출력

p 승객이름 

승객이름에 예약한 항공편을 출력 

q

프로그램 종 


항공편 예약 시스템을 작성하시오.

승객이름은 중복 될수 없다,

동일 예약 판단 구문 작성하시오.


A>

database = []

def reserve(p, f):
global database
if [p, f] not in database:
database.append([p, f])
else:
print("동일 예약이 발견되었습니다.")

def cancle(p, f):
global database
if [p, f] in database:
database.remove([p, f])
else:
print("동일 예약이 발견되지 않았습니다.")

def flight(f):
global database
print("----------------")
print("flight : {}".format(f))
print("----------------")
for data in database:
if data[1] == f:
print(data[0])
print("")

def passenger(p):
global database
print("----------------")
print("passenger : {}".format(p))
print("----------------")
for data in database:
if data[0] == p:
print(data[1])
print("")

def all():
print("-------------------")
print("passenger flight")
print("-------------------")
for data in database:
print("{:<9} {:>6}".format(data[0], data[1]))
print("")

while True:
cmd = input("command : ").split()
code = cmd[0]
if code == "r":
p = cmd[1]
f = cmd[2]
reserve(p, f)
elif code == "c":
p = cmd[1]
f = cmd[2]
cancle(p, f)
elif code == "f":
f = cmd[1]
flight(f)
elif code == "p":
p = cmd[1]
passenger(p)
elif code == "a":
all()
elif code == "q":
break

print(database)


O>

command : r honggildong 101

command : r kimjan 201

command : f 101

----------------

flight : 101

----------------

honggildong


command : f 201

----------------

flight : 201

----------------

kimjan


command : p kimjan

----------------

passenger : kimjan

----------------

201


command : q

[['honggildong', '101'], ['kimjan', '201']]


Process finished with exit code 0

반응형

'Python_Matter > Solve' 카테고리의 다른 글

Python Learn the basics Quiz 38  (0) 2019.06.08
Python Learn the basics Quiz 37  (0) 2019.06.07
Python Learn the basics Quiz 35  (0) 2019.05.25
Python Learn the basics Quiz 34  (0) 2019.05.12
Python Learn the basics Quiz 33  (0) 2019.05.12