0

## [我很爛]SoloLearn|Python 題目

Fill in the blanks to print the first elements of the list, if it contains even number of elements.

list = [1, 2, 3, 4]
if ___ (list) % 2 == 0 ___
print(list[ ___ ] )

“if”後面填三個字，list 裡只能填一個。

### 5 個回答

4
listennn08
iT邦高手 7 級 ‧ 2020-09-30 22:09:24

Fill in the blanks to print the first elements of the list, if it contains even number of elements.

``````list = [1, 2, 3, 4]
if len(list) % 2 == 0:
print(list[0])
``````

1
japhenchen
iT邦大師 1 級 ‧ 2020-09-30 21:28:32

``````list = [1, 2, 3, 4]
s =[ x for x in list if x % 2 == 0 ]
print(s[0])
``````

``````list = [1, 2, 3, 4]
m = next( i for i in list if i % 2 == 0 )
print(m)
``````

``````list = [1, 2, 3, 4]
if for (list) % 2 == 0:
print(list[0])
``````

if for (list) % 2 == 0:
SyntaxError: invalid syntax

2
Tony.Ko
iT邦新手 5 級 ‧ 2020-09-30 22:07:59

Fill in the blanks to print the first elements of the list, if it contains even number of elements.

Tony.Ko iT邦新手 5 級 ‧ 2020-09-30 22:13:31 檢舉

Sololearn的問題答案通常就是該章節所教的語法

0

iT邦新手 5 級 ‧ 2020-09-30 22:16:31

0
8500718
iT邦新手 5 級 ‧ 2020-10-04 00:03:51