python编程面试题
生活随笔
收集整理的這篇文章主要介紹了
python编程面试题
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1. 實現需求為 注冊、登錄、查看昵稱的功能
def userN():username = input("請輸入賬號: \n")password = input('請輸入密碼: \n')return username,passworddef register():# 注冊函數封裝username,password= userN()temp = username + "|" + passwordwith open('D:\Test_Python\login.md','w') as file:file.write(temp)def login():# 登錄函數封裝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 '登錄失敗,請檢查賬號或者密碼'def getNick(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 sysprint('系統已退出,歡迎下次再登錄!')sys.exit(1)def Main():while True:put = int(input('請選擇 1.注冊 2.登錄 3.退出系統'))if put == 1:register()elif put == 2:getNick(login())elif put == 3:exit()else:print('輸入錯誤,請重新輸入...')continueif __name__ == '__main__':Main()2. 列表a = [1,2,3,4,5,6,7],將列表a的值賦給列表b,在不影響列表a的情況下,將列表b的值每間隔一個元素替換成6
''' 遇到問題沒人解答?小編創建了一個Python學習交流QQ群:531509025 尋找有志同道合的小伙伴,互幫互助,群里還有不錯的視頻學習教程和PDF電子書! '''import copya = [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] = 6print(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:passelse:if user == 'Admin' and pwd == '':print('密碼錯誤')if times != 0:print('您還剩'+str(times-1)+'次機會')else:passelse:print('輸入有誤')if times != 0:print('您還剩'+str(times-1)+'次機會')# continueelse:breaktimes -= 1總結
以上是生活随笔為你收集整理的python编程面试题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python中使用for循环,while
- 下一篇: python-封装方法用于读取excel