Ask coding questions

← Back to all posts
Why does it say that the username is the error when you put in your username?
MisledWater79 (0)

I’m trying to make it so if you put in a username it would make a new line in the json file with the username and how much there is in their wallet. It keeps saying that the username is the error so i don’t know what’s wrong. Thanks in advance!

Comments
hotnewtop
robowolf (435)

The error is in line 17. Since 'username' isn't a dictionary you can't use the key 'wallet'.

MisledWater79 (0)

@robowolf Do you know how I might be able to make it work?

robowolf (435)

@MisledWater79 Create 2 lists, one with users, one with wallets. Then append the user and wallet value to the list on a login. When calling it get the index of the user and then call the wallet value based on that index.

usname = input('What is your username?')
user = ['hi']
wallet = [0]
wallval = wallet[user.index(usname)]
MisledWater79 (0)

@robowolf So I tried that and it didn't work but I found another way and if you look at the code now if you type in a username it puts it in the file but if you type in the same name it will just add it again. I believe its something to do with the if statement but I don't know how to fix it.

robowolf (435)

@MisledWater79 On line 8 you forgot to mention what is in users['User']. After 'if' try adding username.

MisledWater79 (0)

@robowolf I fixed that but it still just adds the username again

robowolf (435)

@MisledWater79 Hint: On line 9 users is a dictionary. Try finding a way to narrow it down.