###### tags: `Python`,`TQC` # TQC+ 程式語言Python 708 詞典合併 1. 題目說明: 請開啟PYD708.py檔案,依下列題意進行作答,進行兩詞典合併,使輸出值符合題意要求。作答完成請另存新檔為PYA708.py再進行評分。 2. 設計說明: 請撰寫一程式,自行輸入兩個詞典(以輸入鍵值"end"作為輸入結束點,詞典中將不包含鍵值"end"),將此兩詞典合併,並根據key值字母由小到大排序輸出,如有重複key值,後輸入的key值將覆蓋前一key值。 3. 輸入輸出: 輸入說明 輸入兩個詞典,直至end結束輸入 輸出說明 合併兩詞典,並根據key值字母由小到大排序輸出,如有重複key值,後輸入的key值將覆蓋前一key值 ![](https://i.imgur.com/Lpe7xUd.png) ![](https://i.imgur.com/f2A5zEm.png) ```python= print("Create dict1:") d1 = {} while True: a = input("Key: ") if a == "end": break else: d1[a] = input("Value: ") print("Create dict2:") d2 = {} while True: a = input("Key: ") if a == "end": break else: d2[a] = input("Value: ") d1.update(d2) for i in sorted(d1.keys()): print("{}: {}".format(i,d1[i])) ```