python 練習1(流量控制)

來源:互聯網
上載者:User

標籤:count   blog   break   print   一個   input   bre   使用者名稱   name   

#!/usr/bin/python#_*_ coding:utf-8 _*_

#練習題#1、使用while迴圈輸入 1 2 3 4 5 6 8 9 10 #a.定義一個變數存放數字 #b.用while判斷大於10結束test1=1while test1<=10: print(test1) test1+=1
#2、求1-100的所有數的和 #a.定義一個變數存放和,另外一個變數存放數字 #b.while 迴圈加test2=1count1=0while test2<=100: count1=count1+test2 test2 +=1print(count1)
#3、輸出 1-100 內的所有奇數 #a.定義一個變數存放數字 #b.while 迴圈取2的餘數,如果不為0是奇數test3=1while test3<=100: tf=test3%2 if tf==0: pass else: print(test3) test3 +=1
#4、輸出 1-100 內的所有偶數test4=1while test4<=100: tf=test4%2 if tf==0: print(test4) test4 +=1
#5、求1-2+3-4+5 ... 99的所有數的和 #a.判斷數字寄數用加號,是偶數用減號 #b.輸了等式和結果test5=2stest=‘1‘count2=1while test5<=99: tf=test5%2 if tf == 0: count2=count2 + test5 stest=stest+‘-‘+test5.__str__() else: count2=count2 - test5 stest=stest+‘+‘+test5.__str__() test5 +=1
print(‘{0}={1}‘.format(stest,count2)) #6、使用者登陸(三次機會重試) #a.定義三個變數 #b.擷取使用者輸入名和密碼 #c.判斷是否相等,記不等次數
import getpassname=‘‘passwd=‘‘n=1while n<=3: name=input(‘請輸入使用者名稱:‘) passwd=getpass.getpass(‘請輸入密碼:‘) if name== ‘yjy‘ and passwd == ‘123‘: print(‘恭喜你,登入成功!‘) break else: pass n +=1

python 練習1(流量控制)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.