如何形成for循环?python(空闲) - 表单给定名称,如何输入用户名
例如,我想在名称中有两个单词或三个单词时运行for循环。
我需要使for
循环为不同数目的名称。 例如,对于两个单词,saint christopher
从saint
得到s
并得到christopher
得到schristopher
的结果。
又如,kyrie andrew irving
,我想从andrew
和irving
得到k
从kyrie
,a
得到的kairving
结果。
考虑:
saint christopher
kyrie andrew irving
结果:
schristopher
kairving
我做:
s = ("saint christopher", "kyrie andrew irving")
for s >= 2:
first = s.split()
separate = list(first[0])
secondword = first[1]
firstletter = separate[0]
print(firstletter+secondword)
我应该在哪里解决?
注Stack Overflow是不是免费的代码编写服务。请放下您的代码,以便我们可以专门帮助您编写代码。并阅读https://www.stackoverflow.com/help/how-to-ask以了解如何提出正确的问题。 – SteveFest
你需要阅读关于基本python的教程。 for循环的语法是错误的。您在for循环内的代码并不遥远。 – Steampunkery