Python simple implementation of a random number of bits to generate the password and considerations summary

Source: Internet
Author: User

Python simply implements a password that produces a random number of digits

#!/usr/bin/python
#coding: Utf-8
#产生任意位数的随机密码
Import random,string #导入随机数和字符串模块
x=string.digits+string.letters #将数字和字母的字符串组合赋值给变量x
passwd= ' #原始密码变量是空
a=int (raw_input (' Please enter the number of passwords: ')) #提示用户自定义密码位数, converts the string to a number
for me in Range (a): #循环来实现自定义位数
Tmp=random.choice (x) #注意缩进
Passwd+=tmp #注意缩进
print passwd

Indent a few things to know about

When you start Python, the first thing to focus on is the formatting problem, that is, the code enforces indentation, and as to how much indentation, According to personal habits, the official recommendation is to indent 4 spaces. On the one hand, you can get the programmer to pay attention to formatting and layering habits, on the other hand, it also makes Python code often wrong when testing, here is a summary of several formatting considerations, as well as the implementation of simple random bits of code in Python password.
The same level of code indentation to be consistent, different levels of code can not be on the same indentation.

, where the error is prone to: Tmp=subprocess.call (' ping-c2-i0.2-w1%s &>/dev/null '%x,shell= ' True '), because a line of code is too long and needs to be wrapped, Pycharm will automatically add quotation marks, since the quotation marks are superfluous and delete the added quotation marks, resulting in an error. Thanks to the pycharm will automatically help us do indentation and add the necessary quotation marks, here in the code when the time to do not lily, according to the PYCHARM bit is the format is good.
If the error appears indentationerror, then the description is an indentation error, this time it is necessary to check your code level is the indentation of the problem.

Python simple implementation of the random number of bits generated password and considerations summary

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.