2024-09-30 01:28:50 发布
网友
这是我的剧本:
def makeithappen(): word="" while True: try: word=inputText() except: print("Something happened inputText") else: if len(word)>0: break elif word!=str: break
但是由于某些原因,我得到了一个无效的语法错误,我不知道为什么。在
def makeithappen(): word="" while True: try: word=input() #is this supposed to be input()? except: print("Something happened inputText") else: if len(word)>0: break elif isinstance(word, basestring): #I never got the logic behind it break
我想这就是你想做的。如果输入的文本有效(长度大于0),并且输入类型不是str(在python3的情况下总是false),那么它将退出。在
str
false
#!/usr/bin/python # -*- coding: utf-8 -*- def makeithappen(): word="" while True: try: word=raw_input("Go:") except: print("Something happened inputText") else: if len(word)>0: print("Hello!!") elif word!=str: print("Bye!!") break makeithappen()
我想这就是你想做的。如果输入的文本有效(长度大于0),并且输入类型不是
str
(在python3的情况下总是false
),那么它将退出。在相关问题 更多 >
编程相关推荐