Commit 76120996 by BellCodeEditor

auto save

parent 0db28b07
Showing with 16 additions and 5 deletions
# 臂力挑战赛 # 臂力挑战赛
# 快用你机灵的小脑瓜想想,如何将刘强和他的臂力值自动插入到hero列表中? # 快用你机灵的小脑瓜想想,如何将刘强和他的臂力值自动插入到hero列表中?
name='刘强'
power=66
hero=['赵一',30,'丁二',37,'孙五',52,'王猛',89,'周亮',98] hero=['赵一',30,'丁二',37,'孙五',52,'王猛',89,'周亮',98]
# 自动排序 # 自动排序
name=input('姓名:') #NI JIA YOU倪嘉佑 PU SI QUAN蒲思泉
#因为input函数会强制把输入的内容转换为字符串类型,
#因此需要先转换为整型才能进行数学运算
power=int(input('臂力值:'))
for i in range(len(hero)): for i in range(len(hero)):
# 如果臂力值小于或等于列表中的某一项,就插入到这一项的前面
if i%2==1 and hero[i]>=power: if i%2==1 and hero[i]>=power:
hero.insert(i-1,name) hero.insert(i-1,name)
hero.insert(i,power) hero.insert(i,power)
print(hero) break # 跳出整个循环
\ No newline at end of file # 如果臂力值大于列表中的某一项,就插入到这一项的后面
if hero[len(hero)-1]<power:
hero.append(name)
hero.append(power)
break
print(hero)
# 统计出臂力值排名前三
print(hero[-6:])
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