Please help me to create a program that output a list of possible numbers containing all the numbers in the range N (N is the input number), but there should be no consecutive numbers
Example:
N=4
The range of n = 0,1,2,3
1032 False because (1 behind 0) and (3 behind 2)
1230 False because (1 behind 2) and (2 behind 3)
2031 True because there no two consecutive numbers one behind the other
List=[1302,2031]
Please check this:
n = int(input())
l = list()
i = 0
for j in range(1,n+1):
if j == 0:
l.append(j)
elif j % 2 == 0:
l.insert(0, j)
else:
l.append(j)
print(l)
This actually works only when 'n' is odd. I hope you can figure the even case. If not please let me know
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.