0

I am going through the book 'Python Crash Course' and the problem is as follows:

8-8. User Albums: Start with your program from Exercise 8-7 . Write a while loop that allows users to enter an album’s artist and title . Once you have that information, call make_album() with the user’s input and print the dictionary that’s created . Be sure to include a quit value in the while loop .

I did 8-7 no problem, but trying to add the functionality, the loop to solve 8-7 I can't figure out.

Here was the code I already tried:

    while True: 
        print('Give me an artist.')
        artist=input()
        print('Give me an album.')
        album=input()

        if artist == 'quit':
            break
        elif track_no:
            track_no=input()
            albums = {'Artist': artist, 'Album':album, 'Track Number':track_no}
        else:
            albums = {'Artist': artist, 'Album':album}

    print(albums)



Here is my code from the 8-7 problem:

def make_album(artist, album, track_no=' '):
    if track_no:
        albums = {'Artist': artist, 'Album':album, 'Track Number':track_no}
    else:
        albums = {'Artist': artist, 'Album':album}

    print(albums)
3
  • Where does track no comes from? It is not mentioned in the question. Commented Jul 27, 2019 at 15:50
  • you need to add where are you defining track no variable Commented Jul 27, 2019 at 15:57
  • Sorry, track_no is included in the actual question in the book. I forgot to add it here. It is supposed to be an optional parameter. Commented Jul 27, 2019 at 16:26

3 Answers 3

1

Pass the Input directly to function then print the albums dict in the function.

while True:

    print('Give me an artist.')

    artist=input()
    if artist == 'quit':
        break

    print('Give me an album.')
    album=input()

    print('Give the Track No.')
    track_no=input()

    make_album(artist, album, track_no)

Add the quit condition just after the requesting the artist input otherwise, it will move on to the next input.

Sign up to request clarification or add additional context in comments.

Comments

1

I think this is what you're looking for:

while True: 
    print('Give me an artist.')
    artist=input()
    print('Give me an album.')
    album=input()

    if artist == 'quit':
        break

    make_album(artist, album)

Comments

1
while True: 
    print('Give me an artist.')
    artist=input()
    print('Give me an album.')
    album=input()

    if artist == 'quit':
        print ('Artist': artist, 'Album':album)
        break

1 Comment

This doesn't call make_album().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.