Update 07.字符串和常用数据结构.md

07.字符串和常用数据结构.md

练习2:设计一个函数产生指定长度的验证码,验证码由大小写字母和数字构成。

参考答案:-->报错

UnboundLocalError: local variable 'code' referenced before assignment

增加  code ='' 后解决
pull/550/head
hjmking 2020-04-19 22:19:29 +08:00 committed by GitHub
parent 05998c86e8
commit 70797900fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 1 deletions

View File

@ -456,6 +456,7 @@ def generate_code(code_len=4):
:return: 由大小写英文字母和数字构成的随机验证码
"""
code = ''
all_chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
last_pos = len(all_chars) - 1
code = ''