编写一个名为 weird()
的函数,它将三个字符串作为参数并向后打印最长的一个。 (在平局的情况下,应该选择较早的参数字符串。
函数调用:
weird("I", "Love", "Python")
应导致以下终端输出:
nohtyP
这是我到目前为止所做的..我没有把划痕部分做对......
running = True
while running:
word = raw_input("Enter word:")
if word[0] in "aeiou":
print word + "yay"
else:
print word[1:] + word[0] + "ay"
最佳答案
一个更快的方法(它适用于任意数量的字符串)是:
def weird(*s):
return sorted(s,key=len,reverse=True)[0][::-1]
关于 python - 奇怪的打印......硬件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5587419/