MIT Python second lesson 40th minutes take the minimum value example

Source: Internet
Author: User

Use if to embed minimum value

#取最小值>>> x= the>>> y= One>>> z=5>>>ifX<y and X<z:print ('x is least') Elif y<z:print ('y is the minimum value')Else:p Rint ('Z is least') Z isleast>>>#elifThere's no return, no indentation. >>>#那我用老方法求最小值 What I'm going to write about it:>>> x= the>>> y= One>>> z=5>>>ifx<y:if(x<z): Print ('x is the minimum value')    Else:p Rint ('Z is the minimum value') #因为x <y true, and x<Z falseElse:    if(y<z): Print ('y is the minimum value') #x <y is false, X is not the minimum, as long as Y and Z ratios are fine.Else:p Rint ('Z is the minimum value') z is the minimum value

There are also some syntax errors:

I can't seem to write this: Else:if (y<z):
>>>#so I'm going to use the old method to find the minimum, how do I write it?>>> x=15>>> y=11>>> z=5>>>ifx<y:if(x<z):Print('x is the minimum value')    Else:Print('Z is the minimum value')#because X<y really, and x<z fakeElse:if(y<z): Syntaxerror:invalid syntax
>>> x=15>>> y=11>>> z=5>>>ifx<y:if(x<z):Print('x is the minimum value')    Else:Print('Z is the minimum value')#because X<y really, and x<z fakeElse:if(y<z):Print('y is the minimum value')#X<y is False, X is not the minimum, as long as Y and Z ratios are fine.Syntaxerror:invalid syntax

Professor Grimson: When we write code, especially some code with branching statements, when I design test cases for the code, I should design a special use case for every possible program path.

MIT Python second lesson 40th minutes take the minimum value example

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.