鸿蒙传说
既然你提到用户输入应该只是yes/noor YES/NO,我还添加了一些使用输入和验证它的方法。def validate_input(inp2): if inp2 == 'yes' or inp2 == 'YES' or inp2 == 'no' or inp2 == 'NO': return True else: return Falsedef take_input(self): print("Enter a sentence: ") inp = input() self.vowels.extend([i for i in inp.lower() if i in 'aeiou'])class PrintVowels(): def __init__(self): self.vowels = [] def get_vowels(self): take_input(self) while True: print("Do you want to input more?") inp2 = input() valid_inp = validate_input(inp2) if valid_inp: if inp2.lower() == 'no': break else: take_input(self) else: print("Error: Please try again with a valid input!") continue return self.vowelsob1 = PrintVowels()print (ob1.get_vowels())输出:Enter a sentence: my name is MikeDo you want to input more?blahhhhWHAATError: Please try again with a valid input!Do you want to input more?oopsError: Please try again with a valid input!Do you want to input more?yesEnter a sentence: I am from ChinaDo you want to input more?HuhhhhError: Please try again with a valid input!Do you want to input more?NO['a', 'e', 'i', 'i', 'e', 'i', 'a', 'o', 'i', 'a']