鱼C论坛

 找回密码
 立即注册
查看: 1621|回复: 6

[已解决]求大神给出过程代码

[复制链接]
发表于 2021-4-2 12:55:01 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
python中  1-100数字中所有的3 6 9的数字用x表示的代码


得出的结果大概是1,2,x,4,5,x,7,8,x........22,2x,.................x5,xx,x7,x8,xx,100
最佳答案
2021-4-2 13:15:53
本帖最后由 逃兵 于 2021-4-2 13:23 编辑
  1. num_list = []

  2. for i in range(1,101):
  3.     str_i = str(i)
  4.     str_i = str_i.replace('3','x')
  5.     str_i = str_i.replace('6','x')
  6.     str_i = str_i.replace('9','x')
  7.     num_list.append(str_i)

  8. print(*num_list)
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-4-2 13:11:54 | 显示全部楼层
本帖最后由 591821661 于 2021-4-2 13:16 编辑


满意请设置最佳
  1. string = lambda i: str(i).replace('3','x').replace('6','x').replace('9','x')
  2. print(",".join([string(i) for i in range(1,101)]))

  3. 结果:
  4. 1,2,x,4,5,x,7,8,x,10,11,12,1x,14,15,1x,17,18,1x,20,21,22,2x,24,25,2x,27,28,2x,x0,x1,x2,xx,x4,x5,xx,x7,x8,xx,40,41,42,4x,44,45,4x,47,48,4x,50,51,52,5x,54,55,5x,57,58,5x,x0,x1,x2,xx,x4,x5,xx,x7,x8,xx,70,71,72,7x,74,75,7x,77,78,7x,80,81,82,8x,84,85,8x,87,88,8x,x0,x1,x2,xx,x4,x5,xx,x7,x8,xx,100
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 2 反对 0

使用道具 举报

发表于 2021-4-2 13:15:53 | 显示全部楼层    本楼为最佳答案   
本帖最后由 逃兵 于 2021-4-2 13:23 编辑
  1. num_list = []

  2. for i in range(1,101):
  3.     str_i = str(i)
  4.     str_i = str_i.replace('3','x')
  5.     str_i = str_i.replace('6','x')
  6.     str_i = str_i.replace('9','x')
  7.     num_list.append(str_i)

  8. print(*num_list)
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-4-2 13:18:04 | 显示全部楼层
一行代码给你搞定
  1. print(",".join([str(i).replace('3','x').replace('6','x').replace('9','x') for i in range(1,101)]))
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 1 反对 0

使用道具 举报

发表于 2021-4-2 14:40:10 | 显示全部楼层
本帖最后由 HELLOLIPOP 于 2021-4-2 14:41 编辑
  1. let arr = [];
  2.     for (let i = 1; i <= 100; i++) {
  3.       arr.push(i);
  4.     }
  5.     arr = arr.join(",");
  6.     console.log(arr.replace(/3|6|9/g, "x"));
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 1 反对 0

使用道具 举报

发表于 2021-4-2 17:44:31 | 显示全部楼层
  1. class my_int(int):
  2.     def __repr__(self):
  3.         return super().__repr__().replace('3','x').replace('6','x').replace('9','x')

  4. print(list(map(my_int,range(1,101))))
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-4-4 10:49:04 | 显示全部楼层
感谢大神们的热心指导,我一定会认真学习,虚心请教,感谢大家!!
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-5-17 17:43

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表