Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/342.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 打印从零到输入的所有数字_Python_Python 3.x_Typeerror - Fatal编程技术网

Python 打印从零到输入的所有数字

Python 打印从零到输入的所有数字,python,python-3.x,typeerror,Python,Python 3.x,Typeerror,我正在使用Python3.0,并使用textwrangler和terminal进行编码。代码应该打印从零到输入的所有数字 我正在使用python 3.0 再查一遍。因为您显示的代码显然是Python2.x 要使代码在Python 3.x中工作,需要进行一些修改: 打印是一项功能 raw\u input被重命名为input 这就导致了你的错误。raw\u input(或Python 3.x中的input)的返回值是一个字符串,而您期望的是范围(0,i)中的整数。您需要使用int进行转换。首先,

我正在使用Python3.0,并使用textwrangler和terminal进行编码。代码应该打印从零到输入的所有数字

我正在使用python 3.0

再查一遍。因为您显示的代码显然是Python2.x

要使代码在Python 3.x中工作,需要进行一些修改:

  • 打印
    是一项功能
  • raw\u input
    被重命名为
    input

这就导致了你的错误。
raw\u input
(或Python 3.x中的
input
)的返回值是一个字符串,而您期望的是
范围(0,i)
中的整数。您需要使用
int
进行转换。

首先,作为用户输入的值必须是int,因为您要打印数字。其次,raw_input()在python 3.5.2上不起作用,所以我使用了input()。下面的代码适用于python 3.5.2。试试看

 def func(i):
    numbers=[]
    for x in range(0,i):
        print "At the top x is %d" %x
        numbers.append(x)
        x=x+1
        print "At the bottom x is %d" %x

    print "The numbers:"
    for i in numbers:
        print i

print "I'm going to print the numbers!"
i=raw_input("Enter the number: ")
func(i)
试试这个
print(*list(range(int(input())),sep='')

这甚至不是python-3。这甚至不是问题。1.不是问题。2.提供的信息不正确(不是python 3)。
    def func(i):
   numbers=[]
   for x in range(0, i):
       print ("At the TOP x is %d" %x)
       numbers.append(x)
       x=x+1
       print ("At the bottom x is %d" %x)

   print ("The numbers:")
   for i in numbers:
       print (i)

print ("I'm going to print the numbers!")
i = int(input("Enter the number: "))
func(i)