0

Inside a for loop I have an if statement with a nested if statement inside. then I have 11 elif statements for the outer if statement all with nested if statements inside.

For example:

coins = ['USDT', 'BTC', 'ALPINE', 'USDT']

            for i in range(len(coins) - 1):
                first = coins[I]
                second = coins[i + 1]
               

                if first == 'USDT':
                    if second != 'BUSD' or 'USDC':
                        print('elif Number 1')
                        

                elif first == 'USDT':
                    if second == 'BUSD' or 'USDC':
                        print('elif Number 2')
                        

                elif first != 'USDT' or 'BTC' or 'ETH' or 'BNB' or 'BUSD' or 'USDC':
                    if second == 'BTC' or 'ETH' or 'BNB' or 'BUSD' or 'USDC':
                        print('elif Number 3')
                        

The first iteration of the loop works as intended.

With

first = 'USDT

second = "BTC

The first if statement is used and the outcome is elif number 1

The second iteration of the loop doesn't work.

first = 'BTC'

second = 'ALPINE'

The outcome is elif number 3 which is wrong and the elif statements should filter it into a different outcome.

I have a bunch more elif statements to cover all possible outcomes but it is not being filtered correctly.

What am I missing here?

Callum
  • 67
  • 7
  • pretty sure you're going to need something like `if second != 'BUSD' or second != 'USDC':` since it connects two booleans, and so it will just check if "USDC" is true if it's `if second != 'BUSD' or 'USDC':`. Same for all the others – Pwuurple Jun 01 '22 at 23:48
  • i know this has been closed and i probably shouldn't comment since it's like against some stupid rules, but my recommendation would be something like `if second not in ['BUSD', 'USDC']:` – Pwuurple Jun 01 '22 at 23:54

0 Answers0