求大神给出过程代码
python中1-100数字中所有的3 6 9的数字用x表示的代码得出的结果大概是1,2,x,4,5,x,7,8,x........22,2x,.................x5,xx,x7,x8,xx,100 本帖最后由 591821661 于 2021-4-2 13:16 编辑
满意请设置最佳
string = lambda i: str(i).replace('3','x').replace('6','x').replace('9','x')
print(",".join())
结果:
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 本帖最后由 逃兵 于 2021-4-2 13:23 编辑
num_list = []
for i in range(1,101):
str_i = str(i)
str_i = str_i.replace('3','x')
str_i = str_i.replace('6','x')
str_i = str_i.replace('9','x')
num_list.append(str_i)
print(*num_list)
一行代码给你搞定
print(",".join()) 本帖最后由 HELLOLIPOP 于 2021-4-2 14:41 编辑
let arr = [];
for (let i = 1; i <= 100; i++) {
arr.push(i);
}
arr = arr.join(",");
console.log(arr.replace(/3|6|9/g, "x")); class my_int(int):
def __repr__(self):
return super().__repr__().replace('3','x').replace('6','x').replace('9','x')
print(list(map(my_int,range(1,101)))) 感谢大神们的热心指导,我一定会认真学习,虚心请教,感谢大家!!{:10_265:}
页:
[1]