Commit f3e9a736 by BellCodeEditor

auto save

parent e64f1c1c
Showing with 33 additions and 17 deletions
#臂力挑战赛
#快用你机灵的小脑瓜想想,如何将刘强和他的臂力值自动插入到hero列表中?
name=input("请输入姓名:")
power=int(input("请输入臂力值:"))
name="张三"
power=99
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
s = hero[-6:]
print(s)
# s = hero[-6:]
# print(s)
print(hero)
......
#列表的基本操作
bros = ["刘备","关羽","张飞"]
bros[1] = "刘备"
bros[0] = "关羽"
print(bros)
#列表的删除:pop()/remove()
b=['袁术','夏侯惇','曹操','关羽']
#b.pop(3)
#b.pop(-1)
b.remove("关羽")
print(b)
#列表的增加:insert()\extend()\apend()
a = ['华雄']
c = ['颜良','文丑']
a.extend(c)
print(a)
#切片:
d=['吕布']
e=['袁术','公孙瓒','关羽','张飞','刘备','曹操']
f = e[2:5]
d.extend(f)
print(d)
name="kar98k"
power=99
hero=['丙三',19,'丁二',47,'孙五',55,'王猛',67,'周亮',89,'赵一',97]
for i in range(len(hero)):
    if i%2==1 and hero[i]>=power:
        hero.insert(i-1,name)
        hero.insert(i,power)
        break
s = hero[-6:]
print(s)
\ No newline at end of file
name="kar98k"
name='kar98k'
power=99
hero=['丙三',19,'丁二',47,'孙五',55,'王猛',67,'周亮',89,'赵一',97]
hero=['丙三',19,'丁二',47,'孙五',55,'王猛',67,'周亮',89,'赵一',100]
for i in range(len(hero)):
if i%2==1 and hero[i]>=power:
hero.insert(i-1,name)
......
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