#!/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.