首頁 > 後端開發 > Python教學 > if else流程判斷-CLASS-11(Part 1)

if else流程判斷-CLASS-11(Part 1)

PHP中文网
發布: 2017-07-04 19:30:03
原創
1270 人瀏覽過

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中文網其他相關文章!

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板