if語句的雙分支


以前接觸的語句,if,for,not

age_of_you = 25
if age_of_you > 25:
print("time to find a bf.")
else:
print("還可以再談幾次戀愛。。。")
print("----hhahh")

前倆個print在條件中達到才打印其中一個,很重要很重要,對齊方式

最后一個print兩種情況都會打印,


下面的我必須名字,密碼全輸對,才welcome。。。,不然就wrong。。。
if使用中and的用法,就是兩個條件一起滿足啦,電路中的與或非門一樣的
_username = "shanshan"
_password = "abc123"
username = input("username:")
password = input("password:")

if username == _username and password == _password:
print("welcome",_username)
else:
print("wrong username or password!")





免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM