我是编程新手,需要你的帮助!请看下面的代码,我需要得到工作;
pick_car = raw_input("So whats your favourite car brand then?").lower()
#If raw input contains the name of a car in the cars list then print vehicle brand below
if pick_car in cars:
print 'okay so you like ' + #Car from list
我在代码的顶部有几个列表,其中一个名为cars,其中包含许多汽车品牌。
发布于 2018-06-26 02:33:59
python documentation中提到的raw_input
将返回一个字符串类型的对象。
现在,为了检查字符串中是否出现了任何品牌名称,我们将检查来自cars
的任何品牌名称是否出现在pick cars
中,而不是检查pick car
是否出现在cars
中,如下所示:
pick_car = raw_input("So whats your favourite car brand then?").lower()
for brand_name in cars:
if brand_name in pick_car:
print 'okay so you like ' + brand_name
https://stackoverflow.com/questions/51029398
复制相似问题