import re ''' 输入手机号码,判断手机号码是否为11位,是否为1开头的数值 ''' def get_phone(): while True: phone = input('请输入手机号码:') if len(phone) == 11 and re.match(r'1\d{10}', phone): return phone else: print('请输入11位的手机号') ''' 输入数量,判断数量是否为正整数 ''' def get_amount(): while True: amount = input('请输入数量:') if amount.isdigit() and int(amount) >= 0: return amount else: print('请输入正整数!')
python 判断手机号码和正整数
最新推荐文章于 2023-06-02 17:10:15 发布