A
A
AdvoKappa2020-06-16 21:41:52
Python
AdvoKappa, 2020-06-16 21:41:52

Why does the bot think that a larger value is a smaller one?

The code:

@bot.command()
async def Купить(message):

    with open('coins.json', 'r') as f:
        users = json.load(f)

    with open('coins.json','w') as f:
        json.dump(users, f)

    await update_data(users, message.author)
    await add_coins(users, message.author, 50000)
    await coinss(message, users, message.author)

async def update_data(users, user):
    if not str(user.id) in users:
        users[str(user.id)] = {}
        users[str(user.id)]['coins'] = 0
        users[str(user.id)]['coinss'] = 0

async def add_coins(users, user, coin):
    users[str(user.id)]['coins'] += coin

async def coinss(message, users, user):
    users[str(user.id)]['coinss'] += 15000

    coins = users[str(user.id)]['coins']
    coinss = users[str(user.id)]['coinss']
    if 'coins' > 'coinss':
        await message.channel.send('Да')
    else:
        await message.channel.send('Нет')


Values ​​in JSON file:
{"293396418834464768": {"coins": 50000, "coinss": 15000}}


Returns 'No' even though the first value is greater than the second, how can I fix this? Why does the bot think that the larger value is smaller?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Kuts, 2020-06-16
@AdvoKappa

Because you are comparing two strings, not numbers:
'coins' > 'coinss'

>>> 'coins' > 'coinss'
False

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question