當前位置:成語大全網 - 新華字典 - 三道Python題目求助!

三道Python題目求助!

#第二題:

#沒有辦法寫縮進,看不了下載圖片

dictionary?=?{}

while?True:

response?=?str(input("您要查詢、添加、刪除還是退出字典:?"))

if?response?==?"查詢":

search_response?=?str(input("您要查詢什麽:?"))

if?search_response?in?dictionary:

print(search_response?+?":?"?+?dictionary[search_response])

elif?response?==?"添加":

add_response_name?=?str(input("您要創建新詞的名字:?"))

if?add_response_name?in?dictionary:

add_conform?=?str(input("單詞已存在!您要更改嗎(要/不要):?"))

if?add_conform?==?"要":

add_response_value?=?str(input("您要創建新詞的意思:?"))

dictionary[add_response_name]?=?add_response_value

print("新詞已創建!")?

else:

pass

add_response_value?=?str(input("您要創建新詞的意思:?")

dictionary[add_response_name]?=?add_response_value

print("新詞已創建!")

elif?response?==?"刪除":

delete_response?=?str(input("您要刪除哪個詞:?"))

if?delete_response?not?in?dictionary:

print("該詞不在詞典內!")

else:

del?dictionary[delete_response]

print("該詞已刪除!")

else:

print("程序已退出!")

break