Python下面简单程序能加:如果按"Enter(回车键,或者Esc键)"退出,最好提示Y退出,N不退出。

while True:
input = raw_input('请输入: ')
try:
input = int(input)
if input%2 == 0:
print input," 是偶数:"
else:
print input," 是奇数:"
except:
input = str(input)
if not ' ' in input:
print input,"是字符串,长度为:",len(input)
else:
print input,"是一句子,共有",input.count(' '),"个空格!"
现在按回车键,默认是”0字符串“。一直让你输入,退出不了。除非关闭窗口,有没有内部停止的方法呀?

while True:
    input = raw_input('请输入: ')
    try:
        input = int(input)
        if input%2 == 0:
            print input," 是偶数:"
        else:
            print input," 是奇数:"
    except:
        input = str(input)
        if not len(input):
            inputExit = raw_input('Y退出,N不退出:')
            if  str(inputExit) == 'Y':
                break;
            else:
                continue;
        if not ' ' in input:
            print input,"是字符串,长度为:",len(input)
        else:
            print input,"是一句子,共有",input.count(' '),"个空格!"

温馨提示:答案为网友推荐,仅供参考
相似回答