# 只能输入指定的字符import re repr = '[1|2|3]' #正则表达式while True: char = input('请选择 1 or 2 or 3 :') if re.search(char,repr) == None: print('选择错误!') else: print('选择正确!') break