【发布时间】:2022-10-14 19:45:12
【问题描述】:
我发现打印给定范围内仅包含奇数数字的数字的任务有些困难。 f.e:第一个数字是 2345,第二个数字是 6789。还有一件事 - 打印的数字应该仅限于根据数字位置 2 到 6 (3,5)、3 到 7(3,5) 的范围,7), 4 to 8(5,7), 5 to 9(5,7,9) - 所以这意味着第一个数字应该是 3355,3357,3359,3375,3377,3379,3555,3557.. ..
代码不会按照输出应有的方式执行它:
number_one=int(input())
number_two=int(input())
list_one=[]
list_two=[]
number_one=str(number_one)
number_two=str(number_two)
for i in number_one:
if int(i)==0 or int(i)%2==0:
i=int(i)+1
list_one.append(int(i))
for i in number_two:
list_two.append(int(i))
a=0
b=0
c=0
d=0
for j in range(list_one[0],list_two[0]+1):
if j%2==1:
a=j
for p in range(list_one[1],list_two[1]+1):
if p%2==1:
b=p
for x in range(list_one[2],list_two[2]+1):
if x%2==1:
c=x
for y in range(list_one[3],list_two[3]+1):
if y%2==1:
d=y
print(f"{a}{b}{c}{d}",end=" ")
我想避免输出中有很多重复。
先感谢您!
【问题讨论】:
-
数字总是相同的长度吗?
标签: python for-loop numbers repeat