Python全棧學習筆記day 3
阿新 • • 發佈:2019-01-24
1、格式化輸出
%s %d%%
編碼:
ascii 只能顯示英文,特殊字元,數字。
萬國碼:unicode 最開始16位,中文不夠32位 4個位元組。
佔用資源多。
升級:utf-8 utf-16 utf-32
utf-8:最少用一個位元組,8位表示一個英文。
歐洲16位,兩個位元組。
亞洲 24位,三個位元組。
gbk:中國國產,只能用於中文和ascii碼中的文字。
2,作業講解。
#計算 1 - 2 + 3 ... + 99 中除了88以外所有數的總和 1-2+3.。。,。+99 i=1 sum=0 while i <100: if i==88: i += 1 continue if i%2!=0: sum=sum+i else: sum=sum-i i += 1 print(sum) #計算 1 - 2 + 3 ... -99 中除了88意外所有數的總和 i=0 j=-1 sum=0 while i<99: i=i+1 if i==88: continue else: j = -j sum=sum+i*j print(sum)
⽤戶登陸(三次輸錯機會)且每次輸錯誤時顯示剩餘錯誤次數(提示:使⽤字串格式化)
username = "yangxiaoer" password = "123456" i = 3 while i > 0: zh = input("請輸入你的賬號:") i -= 1 if zh == username: mm = input("請輸入你的密碼:") if mm == password: print("驗證成功.正在登陸......") print('''恭喜你登陸成功! 歡迎使用者進入 使用者名稱 :%s 密碼 :%s '''%(zh,mm)) break else: if i == 0: print("你的機會已經沒了!game over 下次見!") answer = input('再試試?Y or N') if answer == 'Y': i = 3 print("密碼錯誤,請重新輸入") print("你還有"+str(i)+"次機會") else: print("請輸入正確的使用者名稱!") if i == 0: print("你的機會已經沒了!") answer = input('再試試?Y or N') if answer == 'Y': i = 3 print("你還有" + str(i) + "次機會") else: print('你TM要不要臉')
什麼資料型別。
int 1,2,3用於計算。
bool:True,False,使用者判斷。
str:儲存少量資料,進行操作
'fjdsal' '二哥','`13243','fdshklj'
'戰三,李四,王二麻子。。。。'
list:儲存大量的資料。
[1,2,3,'泰哥','12353234',[1,2,3]]
元祖:只讀。
(1,2,3,'第三方',)
dict:字典{'name':'雲姐','age':16}
字典{'雲姐':[],'二哥':[200,200,200,。。。。。。]}
集合:{1,2,34,'asdf'}
3,int。
4,bool。
5,str。