Coming to the close of week 1 learning a programming language (Python)
Looking for general review, comments, and tips
Objective of Code
The objective here was to practice pulling information from dictionaries within lists and also adding dictionaries created from user input.
Code
def make_album(artist, album, tracks =''):
catalog = {}
catalog['artist_name'] = artist
catalog['album_title'] = album
catalog['tracks'] = tracks
return catalog
def ask_user(message):
user_input =''
while not user_input:
user_input = input(message)
return user_input
riven = make_album('Zeppelin', 'Houses of the Holy', 8)
jax = make_album('Tool', 'Lateralus', 13)
vayne = make_album('Pink Floyd', 'Dark Side of the Moon')
differents = [riven, jax, vayne]
while True:
print("type q to quit")
band = ask_user("Enter artist: ")
if band == "q":
break
album = ask_user("Enter album: ")
if album == 'q':
break
numbers = input("Enter number of tracks: ")
if numbers == 'q':
break
fire = make_album(band.title(), album.title(), numbers)
differents.append(fire)
for i in differents:
if i['tracks']:
print('\n' + i['album_title'] + ' by ' \
+ i['artist_name'] + ' it has '\
+ str(i['tracks']) +' tracks.')
else:
print('\n' + i['album_title'] + ' by ' + i['artist_name'] \
+ '.')
Output
vash@localhost:~/pcc/8$ python3 lot2learn.py
type q to quit
Enter artist: circa survive
Enter album: juturna
Enter number of tracks: 11
type q to quit
Enter artist: dance gavin dance
Enter album: happiness
Enter number of tracks:
type q to quit
Enter artist: q
Houses of the Holy by Zeppelin it has 8 tracks.
Lateralus by Tool it has 13 tracks.
Dark Side of the Moon by Pink Floyd.
Juturna by Circa Survive it has 11 tracks.
Happiness by Dance Gavin Dance .
(xenial)vash@localhost:~/pcc/8$