Skip to content

Instantly share code, notes, and snippets.

@oiojin831
Created September 18, 2021 09:32
Show Gist options
  • Save oiojin831/3c57ef287ba3b5cd2505824495550929 to your computer and use it in GitHub Desktop.
Save oiojin831/3c57ef287ba3b5cd2505824495550929 to your computer and use it in GitHub Desktop.
import random
import json
import os
movies = []
file = open(f"{os.getcwd()}/data.json", "r")
line = file.readline()
movies = json.loads(line)
file.close()
while True:
print("1. 영화 추가")
print("2. 영화 보기")
print("3. 랜덤 영화 고르기")
print("4. 영화 감독 추가하기")
print("5. 새로운 속성 추가하기")
print("6. 파일 불러오기")
print("7. 저장후 종료")
num = int(input("번호를 입력해주세요: "))
if num == 1:
title = input("영화제목")
rating = input("영화 평점")
movie = {"title": title, "rating": rating, "director": ""}
movies.append(movie)
elif num == 2:
idx = 0
for movie_data in movies:
print(idx, end=" ")
for data in movie_data.values():
print(data, end=" ")
print("")
idx = idx + 1
elif num == 3:
print(random.choice(movies))
elif num == 4:
movie_num = int(input("영화 번호를 입력해주세요"))
movies[movie_num]["director"] = input("영화 감독을 입력해주세요")
elif num == 5:
movie_num = int(input("영화 번호를 입력해주세요"))
new_key = input("새로운 속성")
new_value = input("새로운 값 ")
movies[movie_num][new_key] = new_value
elif num == 6:
file = open(f"{os.getcwd()}/data.json", "r")
line = file.readline()
movies = json.loads(line)
file.close()
else:
file = open(os.getcwd() + "/data.json", "w")
file.write(json.dumps(movies))
file.close()
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment