Created
July 25, 2021 15:15
-
-
Save oiojin831/d34dc5f9ba37614295b9945c48874cf6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
import os | |
import json | |
movies=[] | |
while True: | |
print("1. 영화를 추가") | |
print("2. 영화 보기") | |
print("3. 랜덤 영화 고르기") | |
print("4. 감독 추가하기") | |
print("5. 새로운 속성 추가") | |
print("6. 파일 불러오기") | |
print("7. 저장후 종료") | |
num = int(input("번호를 입력해 주세요")) | |
if num == 1: | |
movie_title = input("영화 제목을 입력해 주세요") | |
movie_year = input("개봉 연도를 입력 주세요") | |
movies.append({"title": movie_title, "year": movie_year}) | |
elif num == 2: | |
idx = 0 | |
for m in movies: | |
print(idx, m) | |
idx = idx + 1 | |
elif num == 3: | |
ran=random.choice(movies) | |
print(ran) | |
elif num == 4: | |
movie_num = int(input("감독을 추가하고 싶은 메뉴의 번호를 입력해 주세요")) | |
movies[movie_num]["director"] = input("감독를 입력해 주세요") | |
elif num == 5: | |
movie_num = int(input("새오운 속성을 추가하고 싶은 영화의 번호를 입력해 주세요")) | |
new_key = input("새로운 속성의 키(key)를 입력해 주세요") | |
movies[movie_num][new_key] = input("새로운 속성의 값을 입력해 주세요") | |
elif num == 6: | |
file = open(f"{os.getcwd()}/data.json", "r") | |
line = file.readline() | |
movies = json.loads(line) | |
file.close() | |
elif num == 7: | |
file = open(f"{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