Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def song_info(artist_name, song_title, release_date = None): # We give no value to 'release_date'. 'None' is a placeholder
- """Build a dictionary containing information about an album."""
- song_dict = {'artist': artist_name, 'song': song_title} # We add the two arguments provided to the dictionary
- if release_date: # If there is an argument provided for 'release_date' then execute this block.
- song_dict['released'] = release_date # Add the release date to the dictionary.
- return song_dict
- # Prepare the prompts.
- song_prompt = "Which song are you thinking of? "
- artist_prompt = "Who's the artist? "
- released_prompt = "When was it released? "
- while True:
- released = None # We give the 'release' no value so if the user does not provide input for this variable python wont cause
- # any problems
- print("nEnter 'quit' at any time to stop.")
- song = input(song_prompt)
- if song == 'quit':
- break
- artist = input(artist_prompt)
- if artist == 'quit':
- break
- release_question = input("Do you know when it was released?(yes/no) ") # Ask the use if they know the release date.
- if release_question == 'yes': # If they know execute this block.
- released = input(released_prompt) # Ask the user for the release date.
- if released == 'quit':
- break
- elif release_question == 'quit':
- break
- song_info = song_info(artist, song, released)
- print(song_info)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement