Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23131

Bad: so many ifs

$
0
0

In my code with tg bot and database there was a problem with the exchange function. The bot was exchanging some user coins for others. Here is the user model:

class User:    lucky: Mapped[int] = mapped_column(Integer)    chip: Mapped[int] = mapped_column(Integer)    cash: Mapped[int] = mapped_column(Integer)

And this is my function in which I have to check that the coin exchange that comes in the parameters as a string is equal to some of the database and perform the exchange action. Here is the code:

async def trade(callback: CallbackQuery, state: FSMContext):    data = await state.get_data() # here is my data including the number of coins    if data['send_coin'] == 'lucky':        if data['get_coin'] == 'cash'            user = await get_user()            user.lucky -= 10 # update user model            user.cash += 1     # and so on with each coin, that is 6 more ifs

I couldn't google the question, so I asked here.


Viewing all articles
Browse latest Browse all 23131

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>