본문 바로가기
프로그램

[파이썬] 문제 : 음악 플레이리스트 추가,삭제

by 오디세이99 2023. 4. 28.
728x90
반응형

 

playlist = {}

def add_song(song):
    if song not in playlist:
        playlist[song] = True
        print(f"{song} 음악 추가!")
    else:
        print(f"{song} 음악이 이미 았습니다!")

def remove_song(song):
    if song in playlist:
        del playlist[song]
        print(f"{song} 음악삭제")
    else:
        print(f"{song} 음악이 없습니다!")

# 예제 사용법
add_song("음악 1")
add_song("음악 2")
add_song("음악 3")
print(playlist)

add_song("음악 2")
remove_song("음악 2")
print(playlist)

728x90
반응형

댓글