密码生成器v2.9
本帖最后由 shiyouroc 于 2022-3-7 14:59 编辑密码生成器v2.9
问题:
1.代码不简洁。
2.功能不多。
# coding=utf-8
#!/usr/bin/python
# Write Python 3 code in this online editor and run it.
from random import randint
from sys import exit
yes=1
ye=1
xiao=['a','b','c','d','e','f',
'g','h','i','j','k','l',
'm','n','o','q','p','r',
't','s','u','v','w','x','y',
'z']
da=['A','B','C','D','E','F',
'G','H','I','J','K','L',
'M','N','O','P','Q','R',
'T','U','S','V','W','X','Y',
'Z']
def three_engling():
global yes
global ye
yes = input("是1退0")
ye = yes.isdigit()
print(ye)
def tt():
global yes
global ye
while ye == False:
print('请勿非法输入。')
yes = input("是1退0")
ye = yes.isdigit()
print('请勿非法输入。')
if ye == False:
cc()
else:
break
def dd():
global yes
yes = int(yes)
if yes > 1:
print('请勿非法输入。')
cc()
if yes ==0:
exit(0)
def sc():
y=randint(0,2)
if y==0:
d=randint(0,25)
one=xiao
else:
d = randint(0,25)
one = da
if y==1:
q= randint(0,25)
two = xiao
else:
q = randint(0,25)
two = da
if y==2:
z=randint(0,25)
three=xiao
else:
z=randint(0,25)
three=da
numbers = randint(1000000,99999999)
g=str(one)+str(two)+str(three)+'.'+str(numbers)
print(g)
cc()
def cc():
three_engling()
tt()
dd()
sc()
cc()
@python爱好者.
@nizitao @ckblt @冬雪雪冬 xiao=['a','b','c','d','e','f',
'g','h','i','j','k','l',
'm','n','o','q','p','r',
't','s','u','v','w','x','y',
'z']
da=['A','B','C','D','E','F',
'G','H','I','J','K','L',
'M','N','O','P','Q','R',
'T','U','S','V','W','X','Y',
'Z']
这两句代码有些c化 用推导式做比较PYTHON 如果,有bug和建议,请大家评论回复。 第 34 行什么意思? python爱好者. 发表于 2022-3-7 15:00
第 34 行什么意思?
去掉第 34 行!
干嘛要打印是否是数字?! python爱好者. 发表于 2022-3-7 15:00
第 34 行什么意思?
是废话。isdigit()能判断字符串里有没有数字,有返回ture 无flase shiyouroc 发表于 2022-3-7 15:02
是废话。isdigit()能判断字符串里有没有数字,有返回ture 无flase
调试用的? python爱好者. 发表于 2022-3-7 15:02
调试用的?
差不多。 wp231957 发表于 2022-3-7 14:59
xiao=['a','b','c','d','e','f',
'g','h','i','j','k','l',
'm','n','o','q','p','r' ...
啥意思我基本功不太扎实。 shiyouroc 发表于 2022-3-7 15:03
差不多。
加注释,可读性较差
还有请把函数名起的有意义些,更方便阅读,调试! shiyouroc 发表于 2022-3-7 15:04
啥意思我基本功不太扎实。
这个意思:
xiao=['a','b','c','d','e','f',
'g','h','i','j','k','l',
'm','n','o','q','p','r',
't','s','u','v','w','x','y',
'z']
da =
da
['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'Q', 'P', 'R', 'T', 'S', 'U', 'V', 'W', 'X', 'Y', 'Z'] shiyouroc 发表于 2022-3-7 15:04
啥意思我基本功不太扎实。
列表推导式!
还有,尽量避免使用 global 关键语句,
空格空多了点! shiyouroc 发表于 2022-3-7 15:04
啥意思我基本功不太扎实。
在C中也不需要这样写
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
int GetRand(int min, int max)
{
return rand() % (max - min + 1) + min;
}
void GetUsernamePassword(char *username_buff, char *password_buff)
{
int username_len = GetRand(3, 15);
int password_len = GetRand(6, 13);
char *dict = "._1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM";
int dict_len = strlen(dict);
int i;
for(i = 0; i < username_len; ++i)
username_buff = dict;
username_buff = '\0';
for(i = 0; i < password_len; ++i)
password_buff = dict;
password_buff = '\0';
}
int main(void)
{
srand((unsigned int)time(0));
char username_buff;
char password_buff;
for(int i = 0; i < 10; ++i)
{
GetUsernamePassword(username_buff, password_buff);
printf("用户名: %s\n", username_buff);
printf("密码: %s\n", password_buff);
printf("\n");
}
return 0;
}
dd() 和 tt() 是不是应该整合在一起? 好优秀啊 前来学习 {:5_95:} 本帖最后由 nizitao 于 2022-3-14 14:53 编辑
代码问题1.老毛病——空行太多
2.建议将函数、变量的名字改为容易懂的,不然实在看的有些吃力{:10_258:}
3.加注释,加注释,加注释(重要的事情说三遍!!!)
@shiyouroc
页:
[1]