当前位置:网站首页>数字游戏:n人报数,报3的倍数的人离开,其余继续
数字游戏:n人报数,报3的倍数的人离开,其余继续
2022-07-21 08:19:00 【我就叫贝塔】
# 初始值30人
num = [i for i in range(1,31)]
print(len(num))
# 第一个人从5开始报,这里初始值给4
init = 4
# 无限循环,直到剩下2个人停止
while len(num)>2:
print("进入循环")
for i in num:
print("此时的i值为:", i)
# 如果找到3的倍数,将此元素删除
init += 1
print("此时的init值为:", init)
if init % 3 == 0:
print("删除的元素为:", i)
num.remove(i)
print("此时的num为:", num)
# 重新赋值,校正下标
num = num[:]
print(num) [18,28]
边栏推荐
- Advanced C language: data storage (deep analysis - integer)
- 数据库事务隔离级别
- CRM concept: understand the concepts of leads, prospect, MQL and SQL
- HCIP前期总结
- swift 【block】
- 慧荣科技与江波龙协同提升手机存储竞争力
- Mysql07 (data update DML)
- Jupyterhub configuring go environment
- Industrial control software - drive framework
- Screen sharing software --deskreen
猜你喜欢
随机推荐
TinyMCE removes the P tag added by default in the editor line feed
Mysql07 (data update DML)
OSPF知识总结
Mysql06 (sequence)
Deploy server
06-1、友元、初始化列表初始化、nei‘bu
动态规划背包问题——01背包
How to implement an asynchronous network library with go?
What is the difference between int *const p= & I and int const *p= & I
数据库事务隔离级别
Mysql08 (transaction)
2022-7-17 FTP客户端项目实现 - 总结
时间不一致
Interrupt vector table in stm32
Problems and principle analysis of audio AGC
使用CompletableFuture实现异步回调
【集训DAY9】Maze【线段树】
【集训DAY8】Tent【数学】【DP】
【集训DAY9】Light Tank【动态规划】
huawei设置使用账号密码登录