# Python 三元表达式(2) 使用嵌套的三元组表达式统计数字频率,如果是2的倍数加1,如果是4的倍数加2,否则加0 ```python if __name__ == '__main__': pi = [3, 14, 15, 9, 26, 5, 35, 8, 97, 932] even_count = 0 for i in pi: # TODO(You): 请在此实现统计代码 assert even_count == 6 ``` 请选出下列能**正确**实现这一功能的选项。 ## template ```python if __name__ == '__main__': pi = [3, 14, 15, 9, 26, 5, 35, 8, 97, 932] even_count = 0 for i in pi: even_count += 2 if i % 4 == 0 else 1 if i % 2 == 0 else 0 assert even_count == 6 ``` ## 答案 ```python even_count += 2 if i % 4 == 0 else 1 if i % 2 == 0 else 0 ``` ## 选项 ### A ```python even_count += if i % 4 == 0: 2 else: if i % 2 == 0: 1 else: 0 ``` ### B ```python even_count += 1 if i % 2 == 0 else 2 if i % 4 == 0 else 0 ``` ### C ```python even_count += 2 if i % 2 == 0 else 1 if i % 4 == 0 else 0 ```