파이썬

msung99·2022년 4월 25일
0
import random
import time

lunch = ["된장찌개", "피자", "제육볶음", "짜장면"]

while True:
    print(lunch)
    item = input("음식을 추가 해주세요 : ")
    if(item == "q"):
        break
    else:
        lunch.append(item)
print(lunch)

set_lunch = set(lunch)
while True:
    print(set_lunch)
    item = input("음식을 삭제해주세요 : ")
    if(item == "q"):
        break
    else:
        set_lunch = set_lunch - set([item])

print(set_lunch, "중에서 선택합니다.")
print("5")
time.sleep(1)
print("4")
time.sleep(1)
print("3")
time.sleep(1)
print("2")
time.sleep(1)
print("1")
time.sleep(1)
print(random.choice(list(set_lunch)))

total_dictionary = {}

while True:
    question = input("질문을 입력해주세요 : ")
    if question == "q":
        break
    else:
        total_dictionary[question] = ""

for i in total_dictionary:
    print(i)
    answer = input("답변을 입력해주세요 : ")
    total_dictionary[i] = answer
print(total_dictionary)

total_list = []

while True:
    question = input("질문을 입력하세요:")
    if question == "q":
        break
    else:
        total_list.append("질문" : question, "답변" : "")

for dic in total_list:
    print(dic["질문"])
    answer = input("답변을 입력하세요:")
    dic["답변"] = answer

print(total_list)

contacts = ['된장','된장','찌개','국','몰리']
contacts2 = ['된장','찌개','오','유','야']

print(contacts)

print(set(contacts))
print(list(set(contacts)))

final_contacts1 = set(contacts) | set(contacts2)
final_contacts2 = set(contacts) - set(contacts2)
final_contacts3 = set(contacts) & set(contacts2)
print(final_contacts1) 
print(final_contacts2)
print(final_contacts3)

"""
['된장', '된장', '찌개', '국', '몰리']
{'된장', '몰리', '국', '찌개'}
['된장', '몰리', '국', '찌개']
{'몰리', '국', '찌개', '유', '된장', '야', '오'}
{'몰리', '국'}
{'된장', '찌개'}
"""

information = {"고향":"수원", "취미":"영화관람","좋아하는 음식":"국수"}
foods = ["된장찌개", "피자", "제육볶음"]
print(information.get("취미"))
information["특기"] = "피아노"
information["사는곳"] = "서울"
del information["좋아하는 음식"]
print(information)
print(len(information))
information.clear()
print(information)
print(foods[-2])
foods.append("김밥")
del foods[1]
print(foods)
profile
블로그 이전했습니다 🙂 : https://haon.blog

0개의 댓글

관련 채용 정보