223k views
24 votes
Pseudo Design

Design an algorithm in pseudcode which performs the following tasks:
Asks the user to input a new username between 5 and 10 character in length
The main program of the algorithm calls a function called RangeCheck. This function accepts the username, lower limit and upper limit as parameters.
The RangeCheck function validates the username, which should be between 5 and 10 characters (inclusive),
The RangeCheck function returns either True or False depending on whether username is valid or not.
Finally, in the main program of the algorithm, “Username valid” or “Username invalid” is output depending on whether or not the username is valid.
Python Code
Use the above pseudocode design to code the algorithm in Python. Include screenshot evidence of you testing the code with usernames of different of lengths.

User Flanker
by
4.3k points

1 Answer

8 votes

Answer: Here you go, alter these however you'd like

Step-by-step explanation:

Pseudocode:

func RangeCheck(username: string, min: int, max: int): bool {

if username.len >= min && username.len <= max then

return true

return false

}

func main() {

usr = input("> Enter username: ")

if RangeCheck(usr, 5, 10) then println("Username valid.")

else println("Username invalid")

}

Python:

def rangeCheck(username, min, max) -> bool:

if len(username) >= min and len(username) <= max:

return True

return False

def __main__():

usr = input("> Enter username: ")

if rangeCheck(usr, 5, 10): print("Username valid")

else: print("Username invalid")

if __name__ == "__main__":

__main__()

User Unpollito
by
4.8k points