Advertisement
Guest User

Untitled

a guest
Aug 17th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. def song_info(artist_name, song_title, release_date = None): # We give no value to 'release_date'. 'None' is a placeholder
  2. """Build a dictionary containing information about an album."""
  3. song_dict = {'artist': artist_name, 'song': song_title} # We add the two arguments provided to the dictionary
  4. if release_date: # If there is an argument provided for 'release_date' then execute this block.
  5. song_dict['released'] = release_date # Add the release date to the dictionary.
  6. return song_dict
  7.  
  8. release_date = None # We give the 'release_date' no value so if the user does not provide input for this variable python wont cause
  9. # any problems
  10.  
  11. # Prepare the prompts.
  12. song_prompt = "Which song are you thinking of? "
  13. artist_prompt = "Who's the artist? "
  14. released_prompt = "When was it released? "
  15.  
  16. while True:
  17. print("nEnter 'quit' at any time to stop.")
  18.  
  19. song = input(song_prompt)
  20. if song == 'quit':
  21. break
  22. artist = input(artist_prompt)
  23. if artist == 'quit':
  24. break
  25.  
  26. release_question = input("Do you know when it was released?(yes/no) ") # Ask the use if they know the release date.
  27. if release_question == 'yes': # If they know execute this block.
  28. release_date = input(released_prompt) # Ask the user for the release date.
  29.  
  30. if release_date == 'quit':
  31. break
  32.  
  33. elif release_question == 'quit':
  34. break
  35.  
  36.  
  37. song_info = song_info(artist, song, release_date)
  38. print(song_info)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement