2024-05-03 20:10:27 发布
网友
我希望能够接受来自字符串列表的用户输入作为参数,例如
x = get_user_input(['yes', 'no', 'maybe'])
如果用户没有从列表中输入输入。最后,程序应该返回用户选择的列表部分。你知道吗
def get_user_input(allowed_choices): while True: s = raw_input("Enter your choice " + "/".join(allowed_choices) + ": ") if s in allowed_choices: return s x = get_user_input(['yes', 'no', 'maybe'])
如果要进行不区分大小写的比较,请使用s.lower() in allowed_choices。你知道吗
s.lower() in allowed_choices
如果要进行不区分大小写的比较,请使用
s.lower() in allowed_choices
。你知道吗相关问题 更多 >
编程相关推荐