Python Forum
Values not storing in dictonary
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Values not storing in dictonary
#1
def make_album(arist_name, album_title, album_tracks= ""):
	"""Album and arist"""
	album = {
	    'name' : 'arist_name',
	    'album_name' : 'album_title',
	    'tracks' : 'album_tracks',
	    }
	return album

print(make_album('Billy Joel', 'River of Dreams'))

info = make_album('Jimmy Johnson', 'How about them Cowboy\'s')
print(info)

info = make_album('Janet Jackson', 'Nasty Boy\'s')
print(info)

info = make_album('Rolling Stones', 'High Roller', '13')
print(info)
It is supposed to store the values in the dictionary and then print them. Here is the output I get.

Output:
{'name': 'arist_name', 'album_name': 'album_title', 'tracks': 'album_tracks'} {'name': 'arist_name', 'album_name': 'album_title', 'tracks': 'album_tracks'} {'name': 'arist_name', 'album_name': 'album_title', 'tracks': 'album_tracks'} {'name': 'arist_name', 'album_name': 'album_title', 'tracks': 'album_tracks'}
Reply
#2
You need to take the quotes off the values you are setting. Anything in quotes is a string literal. To access the value of the variable you need to remove the quotes.

def make_album(arist_name, album_title, album_tracks= ""):
    """Album and arist"""
    album = {
        'name' : arist_name,
        'album_name' : album_title,
        'tracks' : album_tracks,
        }
    return album
Note that artist should have two t's.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
That worked. Thanks much!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Beginner question - storing values cybertron2 4 3,261 Mar-09-2021, 04:21 AM
Last Post: deanhystad
  Taking user input and storing that to a variable then storing that variable to a list jowalk 12 37,392 Mar-27-2017, 11:45 PM
Last Post: wavic
  Storing and using UI variables values across files xenas 5 4,298 Mar-24-2017, 11:23 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020