[英]How can I limit the number of characters to write and the minimum in an input, Python
[英]How to limit the type of characters input python
如何限制可输入的字符数和字符类型。
s = input('What is your number)
一个数字只能是9位数,所以它应该限制在9位数字和数字
x = input('what is your email address)
电子邮件地址最少包含8个字符,最多包含60个字符,并且必须包含@符号。
我该怎么做呢?
事实上,亲爱的朋友,你不能限制输入功能,但你可以通过这种方式达到你想要的效果:
def isnumber(s):
if s.isdigit() and len(s) <= 9:
return True
else:
print('you should input number and length less than 9')
return False
def main():
s = input('What is your number')
while not isnumber(s):
s = input('What is your number')
print("your number is", s)
if __name__ == "__main__":
main()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.