###给你一个正整数n,例如n=5,则输出:
1 121 12321 1234321 123454321
###思路:这就是1,11,111,1111...的平方,题目不让用字符串做,或者代码不能超过一行见代码:
for i in range(1,int(input())+1): #More than 2 lines will result in 0 score. Do not leave a blank line also
print((10 ** i // 9) ** 2)若可以用字符串:
for i in range(1,int(input())+1): #More than 2 lines will result in 0 score. Do not leave a blank line also
print(*(list(range(1, i)) + (list(range(i, 0, -1)))), sep = "")

本文介绍了一种生成特定正整数序列平方的方法,通过简单的循环结构实现从1到n的数字序列及其反转序列的拼接,并计算其平方。文章提供了两种实现方式,一种适用于不允许使用字符串操作的情况,另一种则利用了字符串操作简化代码。
1206

被折叠的 条评论
为什么被折叠?



