# 1 練習題## 簡述編譯型與解釋型語言的區別,且分別列出你知道的哪些語言屬於編譯型,哪些屬於解釋型# 編譯型:C, 谷歌翻譯,一次翻譯後結果後重復使用# 解釋型:Python, 同聲傳譯,邊執行邊翻譯# 執行 Python 腳本的兩種方式是什麼# 1,交互式,輸入命令後執行# 2,命令行的方式,以文件的方式將代碼永久保存下來# Pyhton 單行註釋和多行註釋分別用什麼?# 單行註釋 ## 多行註釋# '''# '''# 布爾值分別有什麼?# True,Fales# 命名變量注意事項有哪些?# 1,只能使用字母,數字和下劃線# 2,不能使用python的關鍵字# 3,不能以數字開頭# 如何查看變量在內存中的地址?# print(id(xxx))# 寫代碼# 實現用戶輸入用戶名和密碼,當用戶名爲 seven 且 密碼爲 123 時,顯示登錄成功,不然登錄失敗!# 實現用戶輸入用戶名和密碼,當用戶名爲 seven 且 密碼爲 123 時,顯示登錄成功,不然登錄失敗,失敗時容許重複輸入三次# 實現用戶輸入用戶名和密碼,當用戶名爲 seven 或 alex 且 密碼爲 123 時,顯示登錄成功,不然登錄失敗,失敗時容許重複輸入三次# s_un=['seven','alex']# s_pw='123'# tag=True# count=0# while tag:# un=input('your username>>>')# pw=input('your password>>>')# if un in s_un and pw == s_pw:# print('login in')# tag=False# else:# print('your username or password error')# count+=1# if count == 3:# print('account blocked')# tag = False# 寫代碼# a. 使用while循環實現輸出2-3+4-5+6...+100 的和# count=2# res=0# while count<=100:# if count%2 ==1:# res-=count# if count % 2 ==0:# res+=count# count+=1# print(res)# b. 使用 while 循環實現輸出 1,2,3,4,5, 7,8,9, 11,12# count=0# tag=True# while tag:# if count<12:# count+=1# print(count)# if count == 6 or count == 10:# count+=1# continue# 使用while 循環實現輸出 1-100 內的全部奇數# count = 0# tag = True# while tag:# if count < 100:# count += 1# print(count)# if count %2 == 1:# count += 1# continue# e. 使用 while 循環實現輸出 1-100 內的全部偶數# count = 1# tag = True# while tag:# if count < 100:# count += 1# print(count)# if count %2 == 0:# count += 1# continue# 現有以下兩個變量,請簡述 n1 和 n2 是什麼關係?# n1 = 123456# n2 = n1# print(type(n1),type(n2),id(n1),id(n2),n1,n2)# <class 'int'> <class 'int'> 5235232 5235232 123456 123456# 變量值的ID,type,value都相同# 2 做業:編寫登錄接口## 基礎需求:## 讓用戶輸入用戶名密碼# 認證成功後顯示歡迎信息# 輸錯三次後退出程序# dic={# 'aaa':{'pw':'123','count':0},# 'bbb':{'pw':'234','count':0},# 'ccc':{'pw':'456','count':0}# }# tag=True# count=0# while tag:# un=input('your username>>>')# if not un in dic:# print('non username')# count+=1# if un in dic:# pw = input('your password>>>')# if pw == dic[un]['pw']:# print('welcome')# break# else:# print('password error')# count+= 1# if count > 2:# print('account blocked')# break# 升級需求:## 能夠支持多個用戶登陸 (提示,經過列表存多個帳戶信息)# 用戶3次認證失敗後,退出程序,再次啓動程序嘗試登陸時,仍是鎖定狀態(提示:需把用戶鎖定的狀態存到文件裏)dic={ 'aaa':{'pw':'123','count':0}, 'bbb':{'pw':'234','count':0}, 'ccc':{'pw':'456','count':0}}tag=Truecount=0while tag: un=input('your username>>>') if not un in dic: print('non username') count+=1 if un in dic: pw = input('your password>>>') if pw == dic[un]['pw']: print('welcome') break else: print('password error') count+= 1 if count > 2: print('account blocked') break