파이썬 입력 기능 반복 및 출력 기능에 구현 문제에 대해 질문드립니다
조회수 608회
[계속 입력하시겠습니까 메뉴에서 y 를 선택하면 입력 기능을 계속 반복하고 n 을 선택시 최초 나타나는 메뉴를 출력한다.] 라는 명령문을 실행해야 하는데,
def again_product():
이 함수를 사용하게 되면, y와 n 모두 이전에 입력한 내용이 사라집니다. 그리고 메뉴에서 2를 눌렀을 시, 코드가 진행되지 않습니다.
[출력 기능은 다음과 같이 구현하고자 한다.] 1) outputData 함수를 구현하며 메모리에 저장된 데이터를 출력한다.
출력할 데이터는 입력한 데이터 모두를 출력해야 하는데, 어떻게 해결해야 할까요?
class Product:
def __init__(self, name, quantity, date):
self.name= name
self.quantity= quantity
self.date= date
def print_info(self):
print('----------------------')
print('제품명\t''수량\t''생산일')
print('----------------------')
print(self.name, self.quantity, self.date)
def set_product():
name= input('제품명:')
quantity= input('수량:')
date= input('생산일(예:1990-01-01):')
product= Product(name, quantity, date)
return product
def again_product():
# while 1:
ag = {'y': set_product, 'n': print_menu}
again = input('계속 입력 하시겠습니까(y/n)?')
ag[again]()
def print_product(product_list):
for product in product_list:
product.print_info()
def store_product(product_list):
f= open('product_db.txt', 'w')
for product in product_list:
f.write(product.name)
f.write(product.quantity)
f.write(product.date)
f.close()
def read_product(product_list):
f = open('product_db.txt', 'r')
for product in product_list:
r.read(product.name)
r.read(product.quantity)
r.read(product.date)
f.close()
def print_menu():
print('1.입력')
print('2.출력')
print('3.검색')
print('4.종료')
menu= input('메뉴를 선택하세요:')
return int(menu)
def run():
# set_contact()
product_list= []
while 1:
menu= print_menu()
if menu== 1:
product= set_product()
product_list.append(product)
again_product()
elif menu== 2:
print_product(product_list)
elif menu== 3:
search_product(product_list)
elif menu== 4:
break
if __name__ == '__main__':
run()
-
(•́ ✖ •̀)
알 수 없는 사용자
댓글 입력