Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

week 5 assignment problem #5

Open
vellankikoti opened this issue Jun 25, 2018 · 1 comment
Open

week 5 assignment problem #5

vellankikoti opened this issue Jun 25, 2018 · 1 comment

Comments

@vellankikoti
Copy link

    **largest = num if largest<num or largest == None else largest
    smallest = num if smallest>num or smallest == None else smallest**

largest = num if largest>num or largest == None else largest
smallest = num if smallest<num or smallest == None else smallest

@enixdark
Copy link
Owner

enixdark commented Jun 25, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants