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