[python學習]本資料用於理解while循環以及for循環,和預先def 定義的不同和方法。學習資料,不用於其它。


#
__author__:"Gabriel Jason" # date: 2017-11-05 15:38 _user ="Gabriel" _passwd = "222abc" # passed_authentication = False #预先设定为假,本节设定了三种方式,一种是用passed_authenticathon定义,一种是用for..in..;另一种是while counter = 0 while counter <3: # 如果while 后面是 True 就会是死循环。这是重要的while 用法,这是执行三次的意思,和后面的+= 1呼应 #for i in range(3): # 这是for 循环三次 后面break,上面用while 方法循环 username = input("Username:") password = input("Password:") if username == _user and password == _passwd : print("Welcome %s login..." % _user) # passed_authentication = True break # 中断 else: print("Invalid username or passwd") counter += 1 if counter == 3 : keep_going_choice = input("keep going ?你是本人吗? [y/n]") if keep_going_choice == "y": counter = 0 # if not passed_authentication: # 注意 not的用法。 else: # 直接用else可以省去上面的对passed_authentication 定义和判断。 print("you are so low!")

 

posted on 2017-11-05 17:13  金兄的境界-GabrielJason  阅读(192)  评论(0)    收藏  举报

导航