G
G
Guerro692020-05-17 18:18:57
MySQL
Guerro69, 2020-05-17 18:18:57

How to set conditions?

How to set the right conditions?

'''
def give(my_id, user_id, nt_money):
  connect = connection()
  try:
    with connect.cursor() as cursor:
      result = cursor.execute(f'SELECT * FROM accounts WHERE id={user_id}')
      row = cursor.fetchone()
      if result == 1:
        balanc = int(row['balance'])
        balance = int(row['balance'])
'''
        if int(nt_money) > balanc:
          return "На вашем счету не достаточно средст!"
        elif int(nt_money) <= 0:
          return "Нельзя передавать отрицательные суммы!"
        elif int(nt_money) <= balanc:
          balanc -= int(nt_money)
          balance += int(nt_money)
          cursor.execute(f'UPDATE accounts SET balance={balanc} WHERE uid={my_id}')
          cursor.execute(f'UPDATE accounts SET balance={balance} WHERE id={user_id}')
          return f"Вы успешно перевели {nt_money} руб. на счёт пользователя (ID:{user_id})"
          connect.commit()
'''

      elif result == 0:
        return 'Данный пользователь не зарегистрирован!'
  finally:
    connect.close()
'''

It is necessary to set the conditions so as not to allow the user to transfer money more than the balance and not to allow him to transfer a negative amount, I tried to set the conditions in different ways, but nothing sensible came out :(

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question