Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.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_While Loop - Fatal编程技术网

Python 无法正常工作的程序

Python 无法正常工作的程序,python,while-loop,Python,While Loop,我需要写一些程序,直到它找到空间,当它找到空间时,程序停止工作 我一直是个问题。 我的代码: 如果我输入字符串“Hola amigas”,它将返回“Hola”。 我需要没有一些内置的程序/或导入文件功能 我只需要使用while/for循环来实现它 x = raw_input() name = x.split(' ', 1)[0] print name 或 python的方法是这样的: x = raw_input("") name = x.split(" ")[0] print name sp

我需要写一些程序,直到它找到空间,当它找到空间时,程序停止工作

我一直是个问题。 我的代码:

如果我输入字符串“Hola amigas”,它将返回“Hola”。 我需要没有一些内置的程序/或导入文件功能

我只需要使用while/for循环来实现它

x = raw_input()
name = x.split(' ', 1)[0]
print name


python的方法是这样的:

x = raw_input("")
name = x.split(" ")[0]
print name
split
方法将字符串拆分为一个数组,[0]返回该数组的第一项。如果出于某种原因需要索引:

x = raw_input("")
i = x.index(" ")
name = x[:i]
print name

corents
拼写错误,在第5行下方

x  = raw_input("")
i = 0
corents = 0
while(x[i] != " "):
    corents +=i
    i+=1
name = x[:corents]
print name
这是个打字错误。
x = raw_input("")
i = x.index(" ")
name = x[:i]
print name
x  = raw_input("")
i = 0
corents = 0
while(x[i] != " "):
    corents +=i
    i+=1
name = x[:corents]
print name