自動化(Automation)
次のPythonコードを実行した場合に出力される値として正しいものはどれか。 interfaces = {"Gi0/1": "up", "Gi0/2": "down", "Gi0/3": "up", "Gi0/4": "down", "Gi0/5": "up"} count = 0 for intf, status in interfaces.items(): if status == "up": count += 1 print(count)
- ✓3
- B2
- C4
- D5
解説
辞書interfacesのうちstatusが"up"であるものはGi0/1、Gi0/3、Gi0/5の3件であり、ループ処理によりcountは3となる。
根拠CCNP Enterprise公式ページ:300-435 ENAUTO出題範囲『Pythonプログラミング』、基本的なPythonスクリプトの読解