简体   繁体   English

如何创建数字列表

[英]How to create a list of numbers

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 请帮助我创建一个程序,该程序输出可能的数字列表,其中包含N范围内的所有数字(N是输入数字),但不应有连续的数字

Example: 例:

N=4

The range of n = 0,1,2,3 n = 0,1,2,3的范围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. 这实际上仅在“ n”为奇数时有效。 I hope you can figure the even case. 我希望你能弄清偶数情况。 If not please let me know 如果没有,请告诉我

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM