Commit ab2d4b0b by BellCodeEditor

auto save

parent 4448ff54
Showing with 58 additions and 5 deletions
'''
bros=["刘备","关羽","张飞"]
#进行1,2位置交换 一:
bros[0]="关羽"
bros[1]="刘备"
#进行1,2位置交换 二:
bros[0],bros[1]="关羽","刘备"
#进行1,2位置交换 三:
bros[0],bros[1]=bros[1],bros[0]
print(bros)
list=["袁术","刘备","关羽","张飞","曹操"]
list1=["华雄"]
list.remove("关羽")
print(list)
#通过索引插入
#list1.insert(1,"关羽")
#添加到列表末尾
list1.append("关羽")
c=["颜良","文丑"]
#在末尾添加一个列表
list1.extend(c)
print(list1)
'''
list=["袁术","刘备","关羽","张飞","曹操"]
a=["吕布"]
#切片 列表名[索引:索引+1]
print(list[1:4])
a.extend(list[1:4])
print(a)
\ No newline at end of file
# 臂力挑战赛
# 快用你机灵的小脑瓜想想,如何将刘强和他的臂力值自动插入到hero列表中?
name='刘强'
power=40
name=input("请输入您的名字:")
power=int(input("请输入您的臂力值:"))
hero=['赵一',30,'丁二',37,'孙五',52,'王猛',89,'周亮',98]
# 自动排序
print(hero)
\ No newline at end of file
for i in range(1,len(hero),2):
if power<=hero[i]:
hero.insert(i-1,power)
hero.insert(i-1,name)
break #跳出循环
print(hero)
print(hero[-6:])
\ No newline at end of file
# 臂力挑战赛
# 快用你机灵的小脑瓜想想,如何将刘强和他的臂力值自动插入到hero列表中?
name='刘强'
power=int(input("请输入臂力值:"))
hero=['赵一',30,'丁二',37,'孙五',52,'王猛',89,'周亮',98]
# 自动排序
for i in range(1,len(hero),2):
if power <= hero[i]:
hero.insert(i-1,power)
hero.insert(i-1,name)
break
if power > hero[len(hero)-1]:
hero.append(name)
hero.append(power)
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