1. 程式人生 > >python-作業-2

python-作業-2

inpu 註意 class clas print 登陸 -- end bre

小結

1.判斷某個東西是否在某個東西裏面,in or not in,返回結果是布爾值(false or true)

  name = "電磁輻射"
  v = "裏" in name
  print(v)

2. 運算符

  + - * / ** % //

  %號求的是余數,例9%2=1,而//求的是商,如9//2=4

3. break 與 continue 的區別  

i = 0
while i < 10:
    i = i + 1
    print(i)
    continue # or break
    print(test)

print(end)

  continue繼續循環while裏的條件,不執行下面的內容

  break 上面和下面的內容均不執行,直接跳出循環

4. while 與 If 都可以作為條件判斷與else配用,但while可以循環if卻不具備此功能。

i = 0
while i < 10:
    print(i)
    i = i + 1
else:
    print(else)
print(end)

5. 註意print 順序不一樣,輸出結果不一樣

i = 0
while i < 10:
    if i == 7:
        i = i + 1
        continue
    else:
        print(i)
        i 
= i + 1 #不輸出7 ----------------------------------------------------------------------------- i = 0 while i < 10: if i == 7: i = i + 1 continue # break else: i = i + 1 print(i) print(end) #不輸出8

--------------------------------------------------------------------------------------

作業:用戶登陸(三次機會重試)

i = 0
while i < 3:
    user_input = input("請輸入用戶名:")
    user_pwd = input("請輸入密碼:")
    if user_input == "user" and user_pwd == "123456":
        print("歡迎登陸!")
        print(".............")
        break
    else:
        print("用戶名或者密碼錯誤")
    i = i + 1

python-作業-2