Allowed Values Only
This kind of check works like a filter: you need to make sure a list contains no unexpected values. Write a function only_14 that takes a list nums and returns True if every element is either 1 or 4. An empty list also passes, because it contains no invalid elements.
Примеры
Ввод
[1, 4, 1, 4]Вывод
TrueВвод
[1, 4, 2, 4]Вывод
FalseВвод
[1, 1]Вывод
TrueНужно реализовать
def only_14(nums: list[int]) -> bool:
Теги
listsarray
Prihláste sa, aby ste videli históriu odoslaní
Prihlásiť saPrihláste sa, aby ste mohli používať AI mentora
Prihlásiť saVisible tests
1
Input
[1,4,1,4]Expected
True2
Input
[1,4,2,4]Expected
False3
Input
[1,1]Expected
True4
Input
[]Expected
True5
Input
[5]Expected
False6
Input
[4,4,2,1]Expected
FalseFocus radio
Paused · SomaFM · Fluid