Advertisement
Guest User

Untitled

a guest
Aug 18th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 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.  
  9.  
  10. # Prepare the prompts.
  11. song_prompt = "Which song are you thinking of? "
  12. artist_prompt = "Who's the artist? "
  13. released_prompt = "When was it released? "
  14.  
  15. while True:
  16. released = None # We give the 'release' no value so if the user does not provide input for this variable python wont cause
  17. # any problems
  18. print("nEnter 'quit' at any time to stop.")
  19.  
  20. song = input(song_prompt)
  21. if song == 'quit':
  22. break
  23. artist = input(artist_prompt)
  24. if artist == 'quit':
  25. break
  26.  
  27. release_question = input("Do you know when it was released?(yes/no) ") # Ask the use if they know the release date.
  28. if release_question == 'yes': # If they know execute this block.
  29. released = input(released_prompt) # Ask the user for the release date.
  30.  
  31. if released == 'quit':
  32. break
  33.  
  34. elif release_question == 'quit':
  35. break
  36.  
  37.  
  38. song_info = song_info(artist, song, released)
  39. print(song_info)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement