擅长:python、mysql、java
<pre><code>num_of_vlans=input("How many VLANS do you need?: ")
num_of_vlans=int(num_of_vlans)
vlan = {} # Initialized the vlan dict
for i in range(num_of_vlans):
print("Enter Information for vlan {0}".format(i+1))
vlan[i] ={'name':input("Name: "), # Updates the vlan dict in every iteration
'vlan_id':input("ID: "),
'ip':input("IP: "),}
print vlan
</code></pre>
<p>代码中发生的事情是每次重新初始化字典的迭代<code>vlan</code>。应该更新它。你知道吗</p>