Python基礎知識二

來源:互聯網
上載者:User

標籤:div   class   inf   使用者登陸   工作   格式化輸出   輸入   大於   pytho   

一:格式化輸出
現有一練習需求,問使用者的姓名、年齡、工作、愛好 ,然後列印成以下格式
------------ info of Alex Li ------
Name : Alex Li
Age : 22
job : Teacher
Hobbie: girl
------------- end -----------------

第一種方法:
name = input(‘請輸入你的姓名:‘)age = int(input(‘請輸入你的年齡:‘))job = input(‘請輸入你的工作:‘)hobby = input(‘請輸入你的愛好:‘)info = ‘‘‘------------ info of %s ------Name  : %sAge   : %djob   : %sHobbie: %s------------- end ------------‘‘‘%(name,name,age,job,hobby)print(info)

第二種方法:

name = input(‘請輸入你的姓名:‘)age = int(input(‘請輸入你的年齡:‘))job = input(‘請輸入你的工作:‘)hobby = input(‘請輸入你的愛好:‘)info = ‘‘‘------------ info of %(name)s ------Name  : %(name)sAge   : %(age)djob   : %(job)sHobbie: %(hobby)s------------- end -----------------‘‘‘%{‘name‘:name,‘age‘:age,‘job‘:job,‘hobby‘:hobby}print(info)

 

二while   else

使用者登陸(三次之後選擇是否繼續試)

i = 1while i < 4:    username = input(‘請輸入你的姓名:‘)    password = input(‘請輸入你的密碼:‘)    if username == ‘abc‘ and password == ‘ecd‘:        print(‘歡迎‘)        break    else:        print(‘請重新輸入‘)        i += 1        if i == 4:            answer = input(‘是否還要再試試?/Y‘)            if answer == ‘Y‘:                i = 1else:    print(‘滾犢子‘)

 

 

三:邏輯運算子

+       加                              ==        等於

-       減                               !=        不等於

*       乘                               <>       不等於

/       除                               >         小於

//      商                               <         小於                            

%     取餘                            >=      大於等於     

**     冪                                <=      小於等於

四:not,or,and五:編碼的曆史六:in  ,not  in  用法七:作業

 

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.