-1

## A function should store the data into the dictionary ##

albums = {}

def albums(name , artist_type):
    albums = {}
    albums['name'] = 'Name of the artist'
    albums['artist_type'] = 'creation_type'
    print( '\nName :' + name.title())
    print('\nArtist type: ' + artist_type.title())

albums("mike shinoda" , "rapper")

while True:
    name = input("\nEnter your Name ")
    if name == 'q':
        break
    talent = input('Enter your Talent ')
    if talent == 'q':
        break

albums(name , talent)
albums[name] = talent # it shows name 'talent' is not defined
  • Possible duplicate of [How to copy a dictionary and only edit the copy](https://stackoverflow.com/questions/2465921/how-to-copy-a-dictionary-and-only-edit-the-copy) – Ashish Kamble Apr 26 '19 at 11:57

1 Answers1

0

talent lives inside the scope of the while loop, declare it outside:

talent = None
name   = None
while True:
    name = input("\nEnter your Name ")
    ...

albums(name , talent)
albums[name] = talent
Netwave
  • 40,134
  • 6
  • 50
  • 93