Dantheman90
Dantheman90

Reputation: 1

Python list search against Raw_input

I'm very new to coding and could do with your help! Please see below the code which I need to get working;

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

I have a few lists located at the top of my code, one named cars which contains a lot of vehicle brands.

Upvotes: 0

Views: 63

Answers (1)

Idan
Idan

Reputation: 79

raw_input, as mentioned in the python documentation will return a string type object.
Now, to check if any brand name appears in the string, instead of checking if pick car is appearing in cars, we will check if any brand name from cars appears in pick cars, like so:

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

Upvotes: 1

Related Questions