Commit 0b93db99 by BellCodeEditor

auto save

parent 26b3b1d4
Showing with 61 additions and 12 deletions
# 和你的小伙伴用列表讲讲桃园结义的故事,并说说这其中运用了哪些列表知识: #从前啊,有三个bro,分别是:
# 来,我给你起个头~ bro1="刘备"
# 从前啊,有三个bro,分别是:刘备、关羽、张飞... bro2="关羽"
bro1="关羽"
bro2="刘备"
bro3="张飞" bro3="张飞"
bros=["刘备","关羽","张飞"] #他们来到了桃园准备结拜
bro1=["关羽",160,8.5] bros = ["刘备","关羽", "张飞"]
bro2=["刘备",161,9.1] #酒也准备好了,誓词也准备好了,得排个辈分,三人的信息卡是这样的:
bro1=["刘备",161,9.1]
bro2=["关羽",160,8.5]
bro3=["张飞",166,8.3] bro3=["张飞",166,8.3]
bros[0]="关羽" #虽然呢,看起来关羽最年长,但是刘备的综合水平最强,所以,关羽一抱拳,甘为老二,刘备就成了大哥。
bros[1]="刘备" #结拜,大哥自然得站在C位,所以把列表中的刘备替换为关羽,关羽替换为刘备:
print(bros) bros[0] = "关羽"
\ No newline at end of file bros[1] = "刘备"
print(bros)
b=['袁术','夏侯惇','曹操','关羽']
b.remove('关羽')
#或者使用 b.pop(3)
#或者使用 b.pop(-1)
print(b)
#关羽上前迎战,战场上除了华雄还有关羽,得把关羽填到a列表中:
a=['华雄']
a.insert(1, '关羽')
print(a)
#其实啊,在关羽出战之前,袁术说:“可惜我的大将颜良、文丑不在,不然,就不怕华雄了。”那假如颜良、文丑在场并同时出战,你知道该如何用代码表达么?
a= ['华雄']
c=['颜良','文丑']
a.extend(c)
print(a)
\ No newline at end of file
#关羽温酒斩华雄,但毕竟华雄是董卓这边的猛将,董卓得知后,大怒,派吕布前往虎牢关对战.
#吕布勇不可挡,接连杀败八路诸侯。
#一天,他又来挑战,北平太守公孙瓒迎战吕布,没几个回合便败下阵来。
#张飞截住吕布连战五十回合不分胜负。
#关羽见张飞不能取胜,便上前助战,刘备见两个兄弟战不下吕布,也挥动双股剑上前助战.
#终于将吕布打败了。这就是史上有名的三英战吕布。
# 省略繁杂情节,刘关张三人一起冲入战场,围攻吕布:
a=['吕布']
b=['袁术','公孙瓒','关羽','张飞','刘备','曹操']
a.extend(b[2:5])
print(a)
\ No newline at end of file
name='刘强'
power=66
hero=['赵一',30,'丁二',37,'孙五',52,'王猛',89,'周亮',98]
for i in range(len(hero)):
if i%2==1 and hero[i]>=power:
hero.insert(i-1,name)
hero.insert(i,power)
break
print(hero)
\ No newline at end of file
name='刘'
power=66
hero=['赵一',30,'丁二',37,'孙五',52,'王猛',89,'周亮',98]
for i in range(len(hero)):
if i%2==1 and hero[i]>=power:
hero.insert(i-1,name)
hero.insert(i,power)
break
print(hero)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment