while ループを取得してユーザーの入力を検証しようとすると問題が発生し、ユーザーが値を繰り返さないようにします。以下に、私が試した2つの方法を示しますが、それらを機能させる方法がわかりません。
方法 1
def test():
my_list = ["", "", ""]
for i in range(3):
while (my_list[i] != "one") and \
(my_list[i] != "two") and \
(my_list[i] != "three"):
while (my_list[i] == my_list[0]) and \
(my_list[i] == my_list[1]) and \
(my_list[i] == my_list[2]):
text = "Enter, one, two or three", i + 1, ":"
try:
my_list[i] = input(text)
except KeyboardInterrupt:
sys.exit()
print(my_list)
方法 2
def test2():
my_list= ["", "", ""]
while len(my_list)!=len(set(my_list)) == True:
for c in range(4):
while (my_list[i] != "one") and \
(my_list[i] != "two") and \
(my_list[i] != "three"):
text = "Enter, one, two or three", c + 1, ":"
try:
my_list[c] = input(text)
except KeyboardInterrupt:
sys.exit()
print(my_list)