3.if條件判斷
阿新 • • 發佈:2018-11-02
登錄 print style clas 條件 數據 put 控制 簡單實例
1.固定格式
註意: if else 後面的 :不要忘了寫!不要忘了寫!不要忘了寫!
if <條件判斷1>: <執行1> elif <條件判斷2>: <執行2> elif <條件判斷3>: <執行3> else: <執行4>
2.input 控制臺輸入
可以定義一個變量來接收控制臺上輸入的值;
1 name=input("請輸入用戶名")
註意:input返回的數據類型為str,如果想要與數字類型進行比較,需要進行轉換
1 s = input(‘birth:‘) 2 birth = int(s)
3.if 和input 使用的簡單實例理解
1 name=input("請輸入用戶名") 2 code=input("請輸入密碼") 3 if name=="root" and code=="root": 4 print("登錄成功") 5 elif name=="root" and code!="root": 6 print("密碼錯誤") 7 elif name!="root" and code=="root": 8 print("賬號錯誤") 9 else: 10 print("賬號名和密碼錯誤")
3.if條件判斷