Python 第一次作业及解答
本文最后更新于 673 天前,其中的信息可能已经有所发展或是发生改变。

第一次练习


下载习题


1. 姓名


names = ['wjq', 'lys', 'hfcj', 'xhz', 'jcg']
for i in names:
    print(i)

2. 问候


names = ['wjq', 'lys', 'hfcj', 'xhz', 'jcg']
for i in names:
    print(f"hello,{i}!")

3. 嘉宾名单


names = ['wjq', 'hfcj', 'xhz', 'jcg']
for i in names:
    print(f"Hello,{i}! Would you like to have a dinner for me?")

4. 修改嘉宾名单


names = ['wjq', 'hfcj', 'xhz', 'jcg']
for i in names:
    print(f"Hello,{i}! Would you like to have a dinner for me?")
print(f"Unfortunately, {names[1]} couldn't come.")
names[1] = 'mcc'
for i in names:
    print(f"Hello,{i}! Would you like to have a dinner for me?")

5. 添加嘉宾


names = ['wjq', 'hfcj', 'xhz', 'jcg']
print("I have found a bigger table for the party")
names.insert(0, 'lrh')
names.insert(len(names)//2, 'mcc')
names.append('lsh')
for i in names:
    print(f"Hello,{i}! Would you like to have a dinner for me?")

6. 缩减名单


names = ['wjq', 'hfcj', 'xhz', 'jcg']
print("I have found a bigger table for the party")
names.insert(0, 'lrh')
names.insert(len(names)//2, 'mcc')
names.append('lsh')
for i in names:
    print(f"Hello,{i}! Would you like to have a dinner for me?")
print(f"Unfortunately, I could only invite tow guys to the party!")
while(len(names) > 2):
    names.pop()
for i in names:
    print(f"Wow! {i} is still in the list !")
del names[:]
print(names)

7. 放眼世界


locations = ['Singapore', 'Hong Kong', 'Australia', 'Russia', 'Spain', 'France']
for i in locations:
    print(i)
print(sorted(locations))
print(sorted(locations, reverse=True))
print(locations)
locations.reverse()
print(locations)
locations.reverse()
print(locations)
locations.sort()
print(locations)
locations.sort(reverse=True)
print(locations)
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇