drinks = ['cola', 'water', 'beer', 'wine']
drinks = raw_input ("What did you drink? " + print drinks)
所以,基本上我希望程序向用户显示问题,然后打印出可能的答案。用户应该将其中一个键入程序。我尝试了上面的代码,但它不起作用。在drinks
之前打印raw_input
没有意义。我想你也可以这样做:
drinks = ['cola', 'water', 'beer', 'wine']
drinks1 = raw_input("Hai, wanna have a look at the most popular drinks here?")
if drinks1 == "yes":
print drinks
drinks2 = raw_input("So, what did you drink?")
...但有没有比Python更简单的用户可以选择的列表?
提前感谢您的回答。
答案 0 :(得分:1)
一个非常简单的解决方案可能是
if (sLabel.text > 10) {
// imgV.image = [UIImage imageNamed:@"small dot.png"];
}
使用drinks = ['cola', 'water', 'beer', 'wine']
drink = raw_input ("What did you drink? %s" % ', '.join(drinks))
if drink in drinks:
print('you chose ' + drink)
else:
print('invalid choice')
从列表中删除字符串。
答案 1 :(得分:0)
您可以使用strip
和lower
函数编写通用程序。其他一切看起来还不错。
drinks = ['cola', 'water', 'beer', 'wine']
user_input = raw_input("Hai, wanna have a look at the most popular drinks here?")
if user_input.strip().lower() == "yes":
print drinks
drinks2 = raw_input("So, what did you drink?")