day05 作業答案
阿新 • • 發佈:2018-11-07
1. b.不可以 c.
tu=("alex",[11,22,{"k1":"v1","k2":["age","name"],"k3":(11,22,33)},44]) tu[1][2]["k2"].append("Seven") print(tu) d.
tu[1][2]["k3"] 不可以 2. dic={"k1":"v1","k2":"v2","k3":[11,22,33]} a.請迴圈輸出所有的key for a in dic.keys(): print(a) b.請迴圈輸出所有的key for a in dic.values(): print(a) c.請迴圈輸出所有的key和valuesfor a in dic.items(): print(a) d. dic["k4"]="v4" print(dic) e. dic["k1"]="alex" print(dic) f. dic={"k1":"v1","k2":"v2","k3":{1:[11,22,33]}} dic["k3"].append(44) print(dic) g. dic["k3"].insert(1,'18') print(dic) dic.pop('k1') print(dic) 5. li=[11,56,59,52,98,98,65,69,11,32] dic={} list=[] list2=[]for a in li : if a > 66: list.append(a) else : list2.append(a) print(list) dic.setdefault("k1",list) dic.setdefault("k2", list2) print(dic) 6. lst=[1,2,9,3,"name","電腦"] goods=[{"name":"電腦","price":"4855"},{"name":"滑鼠","price":"55"},{"name":"鍵盤","price":"48"}] while 1: xh= input("") if xh.lower()=='q': break elif int(xh) >3 or int(xh) <=0: print("輸入有誤") else: print(xh+goods[int(xh)-1]["name"]+" "+goods[int(xh)-1]["price"])