EDIT:
I ask a user a set of questions from a dictionary:
questions = {
"strong": "Do ye like yer drinks strong? ",
"salty": "Do ye like it with a salty tang? ",
"bitter": "Are ye a lubber who likes it bitter? ",
"sweet": "Would ye like a bit of sweetness with yer poison? ",
"fruity": "Are ye one for a fruity finish? "
}
These keys are associated with another dictionary:
ingredients = {
"strong": ["glug of rum", "slug of whiskey", "splash of gin"],
"salty": ["olive on a stick", "salt-dusted rim", "rasher of bacon"],
"bitter": ["shake of bitters", "splash of tonic", "twist of lemon peel"],
"sweet": ["sugar cube", "spoonful of honey", "splash of cola"],
"fruity": ["slice of orange", "dash of cassis", "cherry on top"]
}
and I ask them the questions through a "simple" if/elif set for each question, and assign their answers to a new dictionary:
beverage = {}
def drink():
"""Find out user preferences and assign to new dictionary"""
if raw_input(questions["strong"]).lower() == "yes":
beverage["strong"] = ingredients["strong"]
elif raw_input(questions["strong"]).lower() == "no":
return False
if raw_input(questions["salty"]).lower() == "yes":
beverage["salty"] = ingredients["salty"]
elif raw_input(questions["salty"]).lower() == "no":
return False
...
drink()
And lastly print beverage:
print beverage
If the user says "yes" it all works well.
BUT, if the user answers "no", the first question is asked again (presumably because of my if/elif structure using raw_input()), and then just skips all the other questions completing the script.
How do I structure it so that if the user says "no" to the first question, it then asks the next question and not each question twice?
printout:
Do ye like yer drinks strong? yes
Do ye like it with a salty tang? no
Do ye like it with a salty tang? yes
Are ye a lubber who likes it bitter? no
Are ye a lubber who likes it bitter? yes
Would ye like a bit of sweetness with yer poison? no
Would ye like a bit of sweetness with yer poison? yes
Are ye one for a fruity finish? no
Are ye one for a fruity finish? yes
Yer cocktail is a made of a
['glug of rum']