You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
no, assume you have largest variable and smallest number with value is 1
now you compare them with num varialbe have value is 2, it means:
if largest < num: // 1 < 2
then assign 'largest' is 'num'
else:
re-assign 'largest' is 'largest'
=> so result of the above is largest = 2
if you use largest = num if largest>num or largest == None else largest
it means:
if largest > num: 1 > 2 -> incorrect, it'll jump to case 'else'
then assign 'largest' is 'num'
else:
re-assign 'largest' is 'largest'
=> so result of the above is 1.
for case use smallest, it's similar.
my code can make you confuse when reading so, i think that you can write clean code by using if..if else..else.
largest = num if largest>num or largest == None else largest
smallest = num if smallest<num or smallest == None else smallest
The text was updated successfully, but these errors were encountered: