"/> ">
if判断语句
<span style="color: #008080">1</span> <span style="color: #0000ff">if</span><span style="color: #000000"> true: </span><span style="color: #008080">2</span> <span style="color: #0000ff">print</span>(<span style="color: #800000">"</span><span style="color: #800000">true</span><span style="color: #800000">"</span><span style="color: #000000">) </span><span style="color: #008080">3</span> <span style="color: #0000ff">else</span><span style="color: #000000">: </span><span style="color: #008080">4</span> <span style="color: #0000ff">print</span>(<span style="color: #800000">"</span><span style="color: #800000">false</span><span style="color: #800000">"</span>)
猜年龄大小
<span style="color: #008080">1</span> <span style="color: #008000">#</span><span style="color: #008000"> Author:dd</span> <span style="color: #008080">2</span> age_of_boy = 56 <span style="color: #008080">3</span> age = int(input(<span style="color: #800000">"</span><span style="color: #800000">age:</span><span style="color: #800000">"</span><span style="color: #000000">)) </span><span style="color: #008080">4</span> <span style="color: #0000ff">if</span> age ==<span style="color: #000000"> age_of_boy: </span><span style="color: #008080">5</span> <span style="color: #0000ff">print</span>(<span style="color: #800000">"</span><span style="color: #800000">you got it</span><span style="color: #800000">"</span><span style="color: #000000">) </span><span style="color: #008080">6</span> <span style="color: #0000ff">elif</span> age ><span style="color: #000000"> age_of_boy: </span><span style="color: #008080">7</span> <span style="color: #0000ff">print</span>(<span style="color: #800000">"</span><span style="color: #800000">you need guess smaller</span><span style="color: #800000">"</span><span style="color: #000000">) </span><span style="color: #008080">8</span> <span style="color: #0000ff">else</span><span style="color: #000000">: </span><span style="color: #008080">9</span> <span style="color: #0000ff">print</span>(<span style="color: #800000">"</span><span style="color: #800000">you need guess bigger</span><span style="color: #800000">"</span>)
对输入密码进行隐藏显示
<span style="color: #008080">1</span> <span style="color: #0000ff">import</span><span style="color: #000000"> getpass </span><span style="color: #008080">2</span> passwd = getpass.getpass(<span style="color: #800000">"</span><span style="color: #800000">input your password:</span><span style="color: #800000">"</span>)
<span style="color: #008080"> 1</span> <span style="color: #008000">#</span><span style="color: #008000"> Author:dd</span> <span style="color: #008080"> 2</span> <span style="color: #0000ff">import</span><span style="color: #000000"> getpass </span><span style="color: #008080"> 3</span> <span style="color: #008080"> 4</span> <span style="color: #008080"> 5</span> _username = <span style="color: #800000">"</span><span style="color: #800000">test</span><span style="color: #800000">"</span> <span style="color: #008080"> 6</span> _passwd = <span style="color: #800000">"</span><span style="color: #800000">111</span><span style="color: #800000">"</span> <span style="color: #008080"> 7</span> <span style="color: #008080"> 8</span> username = input(<span style="color: #800000">"</span><span style="color: #800000">username:</span><span style="color: #800000">"</span><span style="color: #000000">) </span><span style="color: #008080"> 9</span> passwd = getpass.getpass(<span style="color: #800000">"</span><span style="color: #800000">passwd:</span><span style="color: #800000">"</span><span style="color: #000000">) </span><span style="color: #008080">10</span> <span style="color: #0000ff">print</span><span style="color: #000000">(username,passwd) </span><span style="color: #008080">11</span> <span style="color: #008080">12</span> <span style="color: #0000ff">if</span> _username == username <span style="color: #0000ff">and</span> _passwd ==<span style="color: #000000"> passwd: </span><span style="color: #008080">13</span> <span style="color: #0000ff">print</span>(<span style="color: #800000">"</span><span style="color: #800000">user {name} login success</span><span style="color: #800000">"</span>.format(name=<span style="color: #000000">username)) </span><span style="color: #008080">14</span> <span style="color: #0000ff">else</span><span style="color: #000000">: </span><span style="color: #008080">15</span> <span style="color: #0000ff">print</span>(<span style="color: #800000">"</span><span style="color: #800000">login failed</span><span style="color: #800000">"</span>)
<span style="color: #008080"> 1</span> <span style="color: #008000">#</span><span style="color: #008000"> Author:dd</span> <span style="color: #008080"> 2</span> <span style="color: #0000ff">import</span><span style="color: #000000"> getpass </span><span style="color: #008080"> 3</span> <span style="color: #008080"> 4</span> <span style="color: #008080"> 5</span> _username = <span style="color: #800000">"</span><span style="color: #800000">test</span><span style="color: #800000">"</span> <span style="color: #008080"> 6</span> _passwd = <span style="color: #800000">"</span><span style="color: #800000">111</span><span style="color: #800000">"</span> <span style="color: #008080"> 7</span> <span style="color: #008080"> 8</span> username = input(<span style="color: #800000">"</span><span style="color: #800000">username:</span><span style="color: #800000">"</span><span style="color: #000000">) </span><span style="color: #008080"> 9</span> passwd = input(<span style="color: #800000">"</span><span style="color: #800000">passwd:</span><span style="color: #800000">"</span><span style="color: #000000">) </span><span style="color: #008080">10</span> <span style="color: #008080">11</span> <span style="color: #0000ff">if</span> _username == username <span style="color: #0000ff">and</span> _passwd ==<span style="color: #000000"> passwd: </span><span style="color: #008080">12</span> <span style="color: #0000ff">print</span>(<span style="color: #800000">"</span><span style="color: #800000">user {name} login success</span><span style="color: #800000">"</span>.format(name=<span style="color: #000000">username)) </span><span style="color: #008080">13</span> <span style="color: #0000ff">else</span><span style="color: #000000">: </span><span style="color: #008080">14</span> <span style="color: #0000ff">print</span>(<span style="color: #800000">"</span><span style="color: #800000">login failed</span><span style="color: #800000">"</span><span style="color: #000000">) </span><span style="color: #008080">15</span> <span style="color: #0000ff">print</span>(<span style="color: #800000">"</span><span style="color: #800000">ddd</span><span style="color: #800000">"</span>)
以上是if else流程判断-CLASS-11(Part 1)的详细内容。更多信息请关注PHP中文网其他相关文章!