Python父与子的编程之旅 第十二章答案

12-1

arr = []
for i in range(5):
    arr.append(input("input name:"))
print("the names is ",end="")
for j in range(5):
    print(arr[j],end=" ")

12-2

arr = []
for i in range(5):
    arr.append(input("input name:"))
print("the names is ",end="")
for j in range(5):
    print(arr[j],end=" ")
print("") #换行

new_list = arr.sort()
print("the names is ",end="")
for j in range(5):
    print(arr[j],end=" ")

12-3

arr = []
for i in range(5):
    arr.append(input("input name:"))
for j in range(5):
    print(arr[j],end=" ")
print("")#换行
display = int(input("你想显示第几个名字,请输入数字(1-5):"))
print("the %d names is "%display,end="")
print(arr[display - 1]) 

12-4

arr = []
for i in range(5):
    arr.append(input("input name:"))
for j in range(5):
    print(arr[j],end=" ")
print("")#换行
changename = int(input("你想改变第几个名字,请输入数字(1-5):"))
arr[changename - 1] = input("请输入你要更换的名字:")
print("please output all name")
print("the names are ",end="")
for k in range(len(arr)):
    print(arr[k],end=" ")
print("")

12-5

import easygui as gui
simple_dic = {}

while 1:
    add_or_look = gui.enterbox("add or look up a word.(a/l): ")
    if not add_or_look: #在(A/L)界面输入其他数字结束
        break
    if add_or_look == "a" or add_or_look == "l":
        if add_or_look == "a":
            word = gui.enterbox("请输入你要添加的单词:")
            definition = gui.enterbox("请输入该单词的释义:")
            simple_dic[word] = definition
            gui.msgbox("word added")
        else:
            look_up_word = gui.enterbox("请输入要查询的单词:")
            if look_up_word in simple_dic:
                gui.msgbox(simple_dic[look_up_word])
            else:
                gui.msgbox("That word is not in the dictionary yet.")
    else:
        add_or_look = gui.msgbox("指令不正确,请重新输入。 ")
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值