python程式設計面試題

2021-10-07 21:40:56 字數 3004 閱讀 1769

1. 實現需求為 註冊、登入、檢視暱稱的功能

def

usern()

: username =

input

("請輸入賬號: \n"

) password =

input

('請輸入密碼: \n'

)return username,password

defregister()

:# 註冊函式封裝

username,password= usern(

) temp = username +

"|"+ password

with

open

('d:\test_python\login.md'

,'w')as

file

:file

.write(temp)

deflogin()

:# 登入函式封裝

username,password= usern(

)with

open

('d:\test_python\login.md')as

file

: user =

file

.read(

).split(

"|")

if username == user[0]

and password == user[1]

:return

'登入成功'

else

:return

'登入失敗,請檢查賬號或者密碼'

defgetnick

(func)

:# 檢視個人主頁

with

open

('d:\test_python\login.md')as

file

: user =

file

.read(

).split(

"|")

if func:

print

('{}您好,歡迎再次回來!'

.format

(user[0]

))else

:print

('您為進行登入,請登入!'

)def

exit()

:# 退出系統

import sys

print

('系統已退出,歡迎下次再登入!'

) sys.exit(1)

defmain()

:while

true

: put =

int(

input

('請選擇 1.註冊 2.登入 3.退出系統'))

if put ==1:

register(

)elif put ==2:

getnick(login())

elif put ==3:

exit(

)else

:print

('輸入錯誤,請重新輸入...'

)continue

if __name__ ==

'__main__'

: main(

)

2. 列表a = [1,2,3,4,5,6,7],將列表a的值賦給列表b,在不影響列表a的情況下,將列表b的值每間隔乙個元素替換成6

'''

'''import copy

a =[1

,2,3

,4,5

,6,7

] b = a[:]

items =

len(b)

for i in

range(1

,items)

:# print(i)

if i%2==

0:# print(i)

b[i]=6

print

(a)print

(b)[1,

2,3,

4,5,

6,7]

[1,2

,6,4

,6,6

,6]

3.讓使用者輸入使用者密碼,成功列印歡迎資訊,輸錯提示還剩幾次機會,三次機會仍然錯誤退出程式

times =

3while times>0:

user =

input

('請輸入使用者名稱:'

) pwd =

input

('請輸入密碼:'

)if user ==

'admin'

and pwd ==

'admin'

:print

('歡迎進入kz系統'

)if times !=0:

print

('您還剩'

+str

(times-1)

+'次機會'

)else

:pass

else

:if user ==

'admin'

and pwd =='':

print

('密碼錯誤'

)if times !=0:

print

('您還剩'

+str

(times-1)

+'次機會'

)else

:pass

else

:print

('輸入有誤'

)if times !=0:

print

('您還剩'

+str

(times-1)

+'次機會'

)# continue

else

:break

times -=

1

Python程式設計 面試題

1.什麼是lambda函式,有什麼好處?匿名函式,對於只用一次的函式,不需要單獨定義 2.請寫出一段python 實現刪除乙個list裡邊的重複元素 list set lst 3.介紹一下except的用法和作用 try.except.else.finally 異常處理,捕獲出錯異常 4.有沒有乙個...

python語法面試題 python面試題

1.去重,集合 集合的乙個重要特點是 自動去除重複的值 li 1,2,3,1,1,2,2,3,3 去除重複的元素 set set li 轉換為集合,因為集合會自動去重。print set li list set 將集合轉換為列表print li 2.生成器 規則 生成器函式,或者生成器表示式,在呼叫...

程式設計面試題

1.自定義乙個分頁函式,傳參當前頁數 總頁數,輸出以下 1.34567.10 123456.10 1 showpage是掐頭去尾的顯示數量 2 這個函式的重點就在於起始值和結束值的運算 3function page currentpage,totalpages,showpage 5 412 13 p...