问题:要求用户输入一段文字,检验这段文字重复的字,数字,符号,不得超过3次,否则返回重新输入。
要求:使用 count方法,使用列表
完成后追加分数
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!'
# -*- 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()