我正在尝试自己在codeacademy上学习python,我正在查看过去的课程,但我无法弄清楚我做错了什么.我想我正确地复制了一切.
分配是检查用户输入的单词,看它是否包含至少一个字符.如果它确实包含多个字符,程序应该打印用户在开头输入的单词.如果没有,该程序应该说"空".
代码让我输入一个单词,但即使单词有多个字符,它也不会打印出单词.我觉得解决方案可能很简单,但我无法弄明白.我认为分号在正确的空间.我非常感谢你的帮助
print "Welcome to the English to Pig Latin translator!"
original = raw_input("tell me your secrets")
def true_function():
if len(original)>= 1:
print(original)
else:
print("empty")
Run Code Online (Sandbox Code Playgroud)
这是因为你从不打电话给这个true_function()功能.
您可以删除它,只需:
print "Welcome to the English to Pig Latin translator!"
original = raw_input("tell me your secrets")
if len(original)>= 1:
print(original)
else:
print("empty")
Run Code Online (Sandbox Code Playgroud)
或者,true_function()之后调用,将变量original作为参数传递:
def true_function(original):
if len(original)>= 1:
print(original)
else:
print("empty")
print "Welcome to the English to Pig Latin translator!"
original = raw_input("tell me your secrets")
true_function(original)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
159 次 |
| 最近记录: |