Python 无法正常工作的程序
我需要写一些程序,直到它找到空间,当它找到空间时,程序停止工作 我一直是个问题。 我的代码: 如果我输入字符串“Hola amigas”,它将返回“Hola”。 我需要没有一些内置的程序/或导入文件功能 我只需要使用while/for循环来实现它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
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