python基礎練習題

來源:互聯網
上載者:User

標籤:python基礎   inpu   print   ==   while迴圈   三次   bsp   and   nbsp   

1、使用while迴圈輸入 1 2 3 4 5 6     8 9 10
count = 1while count< 11:    if count == 7:           count+=1        continue    print(count)    count+=1

 

2、求1-100的所有數的和
counts = 1num = 0while counts <101:    num +=counts    counts+=1print(num)

  

3、輸出 1-100 內的所有奇數
counte = 1while counte < 101:    if counte % 2 == 1:        print(counte)    counte+=1

  

4、輸出 1-100 內的所有偶數
counte = 1while counte < 101:    if counte % 2 != 1:        print(counte)    counte+=1

  

5、求1-2+3-4+5 ... 99的所有數的和
counte = 1num = 0num1 = 0while counte < 100:    if counte % 2 != 1:        num += -counte    else:        num1 += counte    counte+=1print(num+num1)

  

6、使用者登陸(三次機會重試)
count = 0while count<3:    count +=1    username = input("username:")    password = input("password:")    if username == ‘alex‘ and password == ‘123456‘:        print(‘登陸成功!‘)        break    else:        print(‘請重試!‘)

  

python基礎練習題

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.