Reputation: 1
That is what I have so far and it doesn't work, I am new to Python so sorry if there is a really obvious mistake that I don't see :)
Quotes = ['Iron and Blood' , 'No Quote Available' ]
Blood=Quotes[0]
Else=Quotes[1]
Name = raw_input('Who do you want this humble AI to quote?')
if Name == Bismark:
print(Blood)
Upvotes: 0
Views: 44
Reputation: 6298
You are missing quotes around Bismark if you want to treat it as a string. You want that, because the raw_input
function returns the text the user entered as a string against which you are comparing. This should do the trick:
Quotes = ['Iron and Blood' , 'No Quote Available' ]
Blood=Quotes[0]
Else=Quotes[1]
Name = raw_input('Who do you want this humble AI to quote?')
if Name == 'Bismark':
print(Blood)
That said there are some better and or more 'pythonic' ways to do this. This one uses a dictionary to store quotes:
quotes = {
'Bismark': 'Iron and Blood',
'pep8': 'Variable names should be lower case to make them distinguishable from class names.',
}
not_found = 'No Quote Available'
# this would be just input for python3
name = raw_input('Who do you want this humble AI to quote?')
try:
print(quotes[name])
except KeyError:
print(not_found)
This allows you to add new quotes to the dictionary without adding an if-statement every time.
Upvotes: 2