用python编写一个小程序

问题:要求用户输入一段文字,检验这段文字重复的字,数字,符号,不得超过3次,否则返回重新输入。要求:使用count方法,使用列表完成后追加分数... 问题:要求用户输入一段文字,检验这段文字重复的字,数字,符号,不得超过3次,否则返回重新输入。
要求:使用 count方法,使用列表
完成后追加分数
展开
 我来答
百度网友a148267
推荐于2016-05-22 · TA获得超过2255个赞
知道小有建树答主
回答量:367
采纳率:0%
帮助的人:348万
展开全部

def input_1():

    a = raw_input('Please input something:\n')

    global st

    st = list(a)

    print 'Now the list you just inputted is:\n',st

success = True

while success:

    input_1()

    for i in st:

        c = st.count(i)

        if c >= 3:

            print 'You lost!'

            print 'Error: The number of %s you just input is %s '%(i,c)

            success = True

            break

        print 'The number of %s you inputted is %s time(s)'%(i,c)

        success = False        

print 'Success!'

aid1943
2011-02-17 · TA获得超过237个赞
知道答主
回答量:159
采纳率:0%
帮助的人:114万
展开全部
# -*- coding: cp936 -*-
def checkInput():
success = False
while not success:
userInput = raw_input("请输入一段文字:")
charList = []
for char in userInput:
if char not in charList:
charList.append(char)
if userInput.count(char) > 3:
print "文字重复的字,数字,符号,不得超过3次,请重新输入"
break
else:
print "成功"
success = True

if __name__ == '__main__':
checkInput()
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式