关于加入名单的问题 [英] Question on Joining of list
问题描述
亲爱的小组,
我正在尝试以下代码行:
def try2(n):
a1 = raw_input("打印一个字符串:)
a2 = a1.split()
a3 =God Godess Heaven Sky
for x in a2:
a4 = a3.find(x)
如果a4> -1:
a5 = a3 [a4]
打印a5
elif a4< 0:
a6 = x
打印未找到
打印a6
否则:
打印错误
s = a5 +" + a6
打印s
在这里,如果我放了一个字符串:
Petrol Helium Heaven Sky >
在s中它给了我S Helium
但是我正在寻找a5和a6的输出连接它的所有
值而不是最后的值。你能建议我帮忙吗?我错过了
任何小问题吗?
最好的问候,
Subhabrata。
Dear Group,
I am trying the following code line:
def try2(n):
a1=raw_input("PRINT A STRING:")
a2=a1.split()
a3="God Godess Heaven Sky"
for x in a2:
a4=a3.find(x)
if a4>-1:
a5=a3[a4]
print a5
elif a4<0:
a6=x
print "It is not found"
print a6
else:
print "Error"
s=a5+" "+a6
print s
Here, if I put a string like:
Petrol Helium Heaven Sky
In s it is giving me S Helium
But I am looking for an output of a5 and a6 concatenating all its
values not the last ones. Can you suggest me any help? Am I missing
any minor point?
Best Regards,
Subhabrata.
推荐答案
On Fri,2008年7月18日01:31:59 -0700,SUBHABRATA写道:
On Fri, 18 Jul 2008 01:31:59 -0700, SUBHABRATA wrote:
def try2(n):
a1 = raw_input(" PRINT A STRING:")
a2 = a1.split()
a3 =" God Godess Heaven Sky"
for a in a2:
a4 = a3.find(x)
如果a4> -1:
a5 = a3 [a4]
打印a5
elif a4< 0:
a6 = x
打印" ;找不到
打印a6
否则:
打印错误
s = a5 + " + a6
打印s
在这里,如果我放了一个字符串:
Petrol Helium Heaven Sky >
在s中它给了我S Helium
但是我正在寻找a5和a6的输出连接它的所有
值而不是最后的值。你能建议我帮忙吗?我错过了
任何小问题?
def try2(n):
a1=raw_input("PRINT A STRING:")
a2=a1.split()
a3="God Godess Heaven Sky"
for x in a2:
a4=a3.find(x)
if a4>-1:
a5=a3[a4]
print a5
elif a4<0:
a6=x
print "It is not found"
print a6
else:
print "Error"
s=a5+" "+a6
print s
Here, if I put a string like:
Petrol Helium Heaven Sky
In s it is giving me S Helium
But I am looking for an output of a5 and a6 concatenating all its
values not the last ones. Can you suggest me any help? Am I missing
any minor point?
也许您应该描述输入的内容以及您想要拥有的输出以及输入和输出的连接方式。用文字来说,不是用'b $ b'来代码不是非常清晰的带有编号名称的代码。这是一个愚蠢的想法,并且非常难以理解代码。请使用有意义的名字!
Ciao,
Marc''BlackJack''Rintsch
Maybe you should describe what the input looks like and what output you
want to have and how the input and output are connected. In words, not in
not very clear code with "numbered names". That''s a silly idea and makes
understanding the code very hard. Please use meaningful names!
Ciao,
Marc ''BlackJack'' Rintsch
SUBHABRATA写道:
SUBHABRATA wrote:
我正在尝试以下代码行:
I am trying the following code line:
def try2(n):
user_line = raw_input(" PRINT A STRING:")
user_words = user_line.split()
my_line =" God Godess Heaven Sky" ;
用户名中的单词:
pos = my_line.find(单词)
如果pos> - 1:
first_char = my_line [pos]
print first_char
elif pos< 0:
missing_word = word
print"找不到
print missing_word
else:
print"错误"
s = first_char +" " + missing_word
打印s
try2(1)
你能认出你的代码吗?有了这个快速启动,你应该在
中找到错误没时间;)
def try2(n):
user_line = raw_input("PRINT A STRING:")
user_words = user_line.split()
my_line = "God Godess Heaven Sky"
for word in user_words:
pos = my_line.find(word)
if pos >- 1:
first_char = my_line[pos]
print first_char
elif pos < 0:
missing_word = word
print "It is not found"
print missing_word
else:
print "Error"
s = first_char + " " + missing_word
print s
try2(1)
Do you recognise your code? With that jumpstart you should find the error in
no time ;)
这里,如果我输入一个字符串:
汽油氦天堂天空
s给它S氦气
但是我正在寻找a5和a6的输出连接它的所有
值不是最后一个。你能建议我帮忙吗?我错过了
任何小问题?
Here, if I put a string like:
Petrol Helium Heaven Sky
In s it is giving me S Helium
But I am looking for an output of a5 and a6 concatenating all its
values not the last ones. Can you suggest me any help? Am I missing
any minor point?
是的,使用有意义的变量。他们不会让你的代码神奇地正确
但是会让你更容易找出错误和错误的假设 -
给你和其他人。
Peter
Yes, use meaningful variables. They won''t make your code magically correct
but will make it a lot easier to pinpoint mistakes and false assumptions --
for you and others.
Peter
对不起,如果我没有这么说。
输入是一个字符串Petrol氦天堂天空>
现在,在a3中它是God Goddess Heaven Sky。在那里,
它匹配天堂而不是汽油和氦气,因为它们是
不在a3。
现在,按照代码它给了我一个输出S 天空的并且
氦气
但我正在寻找H S Petrol Helium的输出。而不是S
氦气意思是a5和a6的所有值将在s中连接。
最好的问候,
Subhabrata ..
Marc' 'BlackJack''Rintsch写道:
Sorry if I didn''t say that.
The input is a string "Petrol Helium Heaven Sky"
Now, in a3 it is "God Goddess Heaven Sky" is there,
it is matching Heaven and Sky but not Petrol and Helium as they are
not in a3.
Now, as per the code it is giving me an output "S" of "Sky" and
"Helium"
But I was looking for an output of "H S Petrol Helium" and not "S
Helium" meaning all the values of a5 and a6 will be concatenated in s.
Best Regards,
Subhabrata..
Marc ''BlackJack'' Rintsch wrote:
On Fri,2008年7月18日01:31:59 -0700,SUBHABRATA写道:
On Fri, 18 Jul 2008 01:31:59 -0700, SUBHABRATA wrote:
def try2(n):
a1 = raw_input(" PRINT A STRING:")
a2 = a1.split()
a3 =God Godess Heaven Sky
for x in a2:
a4 = a3.find(x)
如果a4> -1:
a5 = a3 [a4]
打印a5
elif a4< 0:
a6 = x
打印未找到
打印a6
否则:
打印错误
s = a5 +" + a6
打印s
在这里,如果我放了一个字符串:
Petrol Helium Heaven Sky >
在s中它给了我S Helium
但是我正在寻找a5和a6的输出连接它的所有
值而不是最后的值。你能建议我帮忙吗?我错过了
任何小问题?
def try2(n):
a1=raw_input("PRINT A STRING:")
a2=a1.split()
a3="God Godess Heaven Sky"
for x in a2:
a4=a3.find(x)
if a4>-1:
a5=a3[a4]
print a5
elif a4<0:
a6=x
print "It is not found"
print a6
else:
print "Error"
s=a5+" "+a6
print s
Here, if I put a string like:
Petrol Helium Heaven Sky
In s it is giving me S Helium
But I am looking for an output of a5 and a6 concatenating all its
values not the last ones. Can you suggest me any help? Am I missing
any minor point?
也许您应该描述输入的内容以及您想要拥有的输出以及输入和输出的连接方式。用文字来说,不是用'b $ b'来代码不是非常清晰的带有编号名称的代码。这是一个愚蠢的想法,并且非常难以理解代码。请使用有意义的名字!
Ciao,
Marc''BlackJack''Rintsch
Maybe you should describe what the input looks like and what output you
want to have and how the input and output are connected. In words, not in
not very clear code with "numbered names". That''s a silly idea and makes
understanding the code very hard. Please use meaningful names!
Ciao,
Marc ''BlackJack'' Rintsch
这篇关于关于加入名单的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!