추천 메뉴의 수와 이름이 주어질 때, 무작위로 선택하는 문제이다.
각 추천에서 메뉴명들을 리스트 형태로 menu 리스트에 저장하고
random 모듈의 choice() 함수로 리스트에서 무작위로 element를 선택하도록 한다.
import random
menu=[]
n=int(input())
for _ in range(n):
num, *name=input().split()
menu.append(name)
random_menu=random.choice(menu)
print(len(random_menu))
print(*random_menu, sep='\n')
'BOJ > Python' 카테고리의 다른 글
[BOJ/백준] 30156 - Malvika is peculiar about color of balloons (Python) (0) | 2024.09.09 |
---|---|
[BOJ/백준] 20352 - Circus (Python) (1) | 2024.09.08 |
[BOJ/백준] 20233 - Bicycle (Python) (1) | 2024.09.08 |
[BOJ/백준] 28453 - Previous Level (Python) (0) | 2024.09.04 |
[BOJ/백준] 28248 - Deliv-e-droid (Python) (0) | 2024.09.04 |