dimanche 24 octobre 2021

Assign to variable inside one line if-else statement

I want to assign to global variable in a one line if-else statement

The statement in one line:

wins += 1 if num > num2 else lose += 1;

I get invalid syntax error, with one line.

The original statement is working:

if num > num2:
    wins += 1
else:
    lose += 1  

I'm using more than 5000 statements, each one line and separate with semicolon ; to make it all one line.

Aucun commentaire:

Enregistrer un commentaire