if else否则声明与字母(A,B,C或D)的问卷

时间:2015-12-12 03:24:33

标签: python

我需要帮助我的if / else语句用于哪个奇迹字符问卷如何添加"而#34;使python编码正确。谢谢。我想确保他们不能输入除A,B,C或OR之外的任何字母。

if str(input())) not ('A','B','C','D')
else ("ask them again");

2 个答案:

答案 0 :(得分:1)

一个简单的选项是检查每个字母:

choice='f'
while choice!='A' and choice!='B' and choice!='C' and choice!='D':
  choice=input('Enter letter')

如果您想在.upper()

之后立即使用input(..)进行检查

答案 1 :(得分:1)

answer = ""
possibleAnswers = {"A","B","C","D"}

while answer not in possibleAnswers:
    answer = input("Select an answer:")