V
V
Viktor2021-07-07 15:40:29
Python
Viktor, 2021-07-07 15:40:29

I seemed to be sick when the topic of concatenation was, what does he want from me?

I continue to write a Casino with a database in *.txt, everything seems to work, but if the bet is more than the bank, it gives an error. Help, I'm tired of rearranging int and str by variables, the errors change, but do not disappear.

Traceback (most recent call last):
File "C:\Users\...\main.py", line 42, in
bet()
File "C:\Users\...\main.py", line 19, in bet
check_bet(bet)
File "C:\Users\...\main.py", line 30, in check_bet
bet()
TypeError: 'int' object is not callable


The code:
#v0.05
from random import randint
import sys


def user_data(id):
    with open('db.txt', 'r') as db:
        for line in db.readlines():
            if str(id) in line:
                user_data = line.split()
                u_bank = user_data[2]
                u_name = user_data[1]
                u_id = user_data[0]
                return u_id, u_name, u_bank


def bet():
    bet_in= input('Сколько ставишь:') #!!!проверить незарегистрированного пользователя!!!
    bet = int(bet_in)
    check_bet(bet)
    get_bet(bet)
    reply()


def check_bet(bet):
    u_id, u_name, u_bank = user_data(id_in)
    int_bank = int(u_bank)
    int_bet = int(bet)
    if int_bet > int_bank:
        print('Ты не можешь столько ставить, твой банк: ' + str(u_bank))
        bet()


id_in = input('введи айди')#Регистрация
with open('db.txt', 'r+') as db: # Проверка пользователя в db
        if id_in in db.read():
            u_id, u_name, u_bank = user_data(id_in)
            bank = int(u_bank)
            if bank < 0:
                sys.exit('Где бабки, Лебовски!!!')
            else:
                input('Приветствую, ' + u_name + ' твой банк: ' + str(u_bank))
                bet()
        else:
            user_name = input('введи имя')
            db.write('\n' + id_in + ' ' + user_name + ' 666')
            print('Рад знакомству, ' + user_name + ' начислил вам 666 очков!')


def check_bank(bank):
    u_id, u_name, u_bank = user_data(id_in)
    if bank <= 0:
        write_db(u_id, 0)
        print('Закончились кровные, обратись к админу!')


def get_bet(bet):
    r_num = randint(1,100)
    u_id, u_name, u_bank = user_data(id_in)
    int_bank = int(u_bank)
    check_bet(bet)
    if r_num > 50:
        int_bank += bet
        write_db(u_id, int_bank)
        print('Выпало ' + str(r_num) + ', ты выиграл ' + str(bet) + ' мои поздравления!\nБанк ' + str(int_bank))

    else:
        int_bank -= bet
        check_bank(int_bank)
        if int_bank !=0:
            write_db(u_id, int_bank)
            print('Выпало ' + str(r_num) + ', ты потерял ' + str(bet) + ' попробуй снова\nБанк ' + str(int_bank))
            check_bank(int_bank)


def write_db(id_in,w_bank):
    with open('db.txt', 'r') as db:
        data = db.read()
        u_id, u_name, u_bank = user_data(id_in)
        old_data = u_id + ' ' + u_name + ' ' + str(u_bank)
        new_data = u_id + ' ' + u_name + ' ' + str(w_bank)
        w_user_data = data.replace(old_data, new_data)
    with open('db.txt', 'w') as db:
        db.write(w_user_data)


def reply():
    reply_an = input('Сыграем еще?(да/нет):')
    if reply_an.lower() == 'да':
        bet()

bet()

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
soremix, 2021-07-07
@Badmajor

Use different names.
Here bet is a function
def bet():
Here it is already a number
bet = int(bet_in)

D
dooMoob, 2021-07-07
@dooMoob


def bet():
    bet_in= input('Сколько ставишь:') #!!!проверить незарегистрированного пользователя!!!
    bet = int(bet_in)
    check_bet(bet)
    get_bet(bet)
    reply()


def check_bet(bet):
    u_id, u_name, u_bank = user_data(id_in)
    int_bank = int(u_bank)
    int_bet = int(bet)
    if int_bet > int_bank:
        print('Ты не можешь столько ставить, твой банк: ' + str(u_bank))
        bet()


Instead of permuting int and str by variables, you just need to turn on your head and look at this piece of "code"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question