import json
import os
DATA_FILE = "restaurant_reviews.json"
def load_data():
if os.path.exists(DATA_FILE):
with open(DATA_FILE, "r", encoding="utf-8") as f:
return json.load(f)
return []
def save_data(data):
with open(DATA_FILE, "w", encoding="utf-8") as f:
json.dump(data, f, ensure_ascii=False, indent=2)
def get_score_input(prompt):
while True:
try:
score = int(input(f"{prompt} (1~5): "))
if 1 <= score <= 5:
return score
else:
print("⚠️ 1에서 5 사이의 숫자를 입력해주세요.")
except ValueError:
print("⚠️ 숫자만 입력 가능합니다.")
def score_to_stars(score):
return '★' * score + '☆' * (5 - score)
def add_review(data):
print("\n[맛집 평가 입력]")
name = input("가게 이름: ")
taste = get_score_input("맛")
price = get_score_input("가격 대비 만족도")
service = get_score_input("서비스")
cleanliness = get_score_input("청결도")
atmosphere = get_score_input("분위기")
revisit = input("재방문 의사 (예/아니오): ")
evaluation = input("이 가게에 대한 평가를 남겨주세요: ")
review = {
"가게 이름": name,
"맛": taste,
"가격": price,
"서비스": service,
"청결": cleanliness,
"분위기": atmosphere,
"재방문 의사": revisit,
"평가": evaluation
}
data.append(review)
save_data(data)
print("✅ 리뷰가 저장되었습니다.")
def show_reviews(data):
print("\n[전체 맛집 리뷰]")
for i, r in enumerate(data, 1):
print(f"\n{i}. {r['가게 이름']} — \"{r['평가']}\"")
print(f" 맛: {score_to_stars(r['맛'])}")
print(f" 가격: {score_to_stars(r['가격'])}")
print(f" 서비스: {score_to_stars(r['서비스'])}")
print(f" 청결: {score_to_stars(r['청결'])}")
print(f" 분위기: {score_to_stars(r['분위기'])}")
print(f" 재방문 의사: {r['재방문 의사']}")
def main():
data = load_data()
while True:
print("\n--- 맛집 평가 프로그램 ---")
print("1. 리뷰 작성")
print("2. 전체 리뷰 보기")
print("3. 종료")
choice = input("메뉴 선택: ")
if choice == "1":
add_review(data)
elif choice == "2":
show_reviews(data)
elif choice == "3":
print("👋 프로그램을 종료합니다.")
break
else:
print("⚠️ 메뉴 번호를 다시 확인해주세요.")
if __name__ == "__main__":
main()