0

我需要为下面的随机密码生成器编写一个伪代码。我该如何编写伪代码 请帮帮我。谢谢你。

import random
import string

print('hello, Welcome to Password generator!')

l = False
while not l:
    length = int(input('\nEnter the length of password: '))
    if length < 8 :
        print('You password length is too short(must be more than 8 character)')
        print(length, "is the length of your password")
    elif length > 16:
            print('You password length is too long(must be less than 17 character)')
            print(length, "is the length of your password")
    else:
            print('You password length looks good')
            break

lower = string.ascii_lowercase
upper = string.ascii_uppercase
num = string.digits
symbols = string.punctuation

all = lower + upper + num + symbols

temp = random.sample(all,length)

password = "".join(temp)

print(password)
4

2 回答 2

0

这够好吗?

IMPORT random
IMPORT string

OUTPUT('hello, Welcome to Password generator!')

SET l TO False
WHILE not l:
    SET length TO int(INPUT('\nEnter the length of password: '))
    IF length < 8 :
        OUTPUT('You password length is too short(must be more than 8 character)')

        OUTPUT(length, "is the length of your password")

    ELSEIF length > 16:

            OUTPUT('You password length is too long(must be less than 17 character)')

            OUTPUT(length, "is the length of your password")

    ELSE:
            OUTPUT('You password length looks good')
            break

SET lower TO string.ascii_lowercase
SET upper TO string.ascii_uppercase
SET num TO string.digits
SET symbols TO string.punctuation
SET all TO lower + upper + num + symbols
SET temp TO random.sample(all,length)
SET password TO "".join(temp)
OUTPUT(password)

或者这个:

DECLARE length<-int(input('\nEnterthelengthofpassword:')) : INTEGER
import random
import string

OUTPUT 'hello, Welcome to Password generator!'

l<-False
WHILE not l DO
INPUT length<-int(input('\nEnterthelengthofpassword:'))
    IF length < 8 
        THEN
        OUTPUT 'You password length is too short(must be more than 8 character'
        OUTPUT length, "is the length of your password"
    ENDIF
    elif length > 16:  //You will need to change this to CASE OF
            OUTPUT 'You password length is too long(must be less than 17 character'
            OUTPUT length, "is the length of your password"
    ELSE
            OUTPUT 'You password length looks good'
            break  //This might be better as a repeat loop
ENDWHILE

lower<-string.ascii_lowercase
upper<-string.ascii_uppercase
num<-string.digits
symbols<-string.punctuation

all<-lower + upper + num + symbols

temp<-random.sample(all,length)

password<-"".join(temp)

OUTPUT password

Process finished with exit code 0

于 2022-01-19T02:56:40.153 回答
0

伪代码是一种代码,旨在显示特定算法的步骤。对于这个算法,它可能看起来像这样。

output "Welcome"
l := false
while l is not true do
    length := int value of input("Enter length of password: ")
    if length < 8 do
        output "Your password is too short"
    else if length > 16 do
        output "Your password is too long"
    else do
        output "Password length looks good"
        break from loop
    endif
endwhile

lower := array of lowercase letters
upper := array of uppercase letters
numbers := array of digit characters
symbols := array of punctuation characters

all := lower combined with upper combined with numbers combined with symbols
temp := random sample of all, with length len
password := join "" with temp
output password

有关伪代码的更多阅读,请查看此链接:https ://en.wikipedia.org/wiki/Pseudocode

于 2022-01-19T02:59:18.020 回答