I am making a text adventure game as part of my Learning Python book ... Anyway, this is what I am trying to do:
def is_a_song(song):
valid_sung_songs = ["song 1", "song 2", "song 3"]
valid_unsung_songs = ["s1", "s2", "s3"]
if song.lower() in valid_sung_songs:
return (True, 0)
elif song.lower() in valid_unsung_songs:
return (True, 1)
else:
return False
def favorite_song():
choice = raw_input("> ")
is_song, has_sung = is_a_song(choice)
if is_song and (has_sung == 0):
print "Good Song"
elif is_song and (has_sung == 1):
print "Good Song, But I haven't sung it"
else:
print "Not a valid song"
favorite_song()
Now this is just an abridged version of the code that I actually used, but when it is executed, it works when the song is valid and executed, when it is valid and non-sung, but it crashes in the last else statement:
else:
print "Not a valid song"
With an error:
TypeError: 'bool' object is not iterable
If you need the actual code that I use, it is here:
source
share