1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
polet [3.4K]
3 years ago
5

You have been asked to write a username validation program for a small website. The website has specific rules on what constitut

es a valid username, including:
All usernames must be between 8 and 15 characters long

Usernames can only contain alphabetic (a-z and A-Z) and numeric characters (0-9) - no special characters are allowed.

The first character in a username cannot be a digit
Usernames must contain at least one uppercase character
Usernames must contain at least one lowercase character
Usernames must contain at least one numeric character

Write a program that asks the user to enter in a username and then examines that username to make sure it complies with the rules above. Here's a sample running of the program - note that you want to keep prompting the user until they supply you with a valid username:

a.Please enter a username: foo
Username must be between 8 and 15 characters.

b.Please enter a username: fooooooooooooooooooo
Username must be between 8 and 15 characters.

c.Please enter a username: foo ooo ooo
Username must contain only alphanumeric characters.

d.Please enter a username: foooooooooo
Your username must contain at least one digit

e.Please enter a username: 1fooooooooo
The first character in your username cannot be a digit

f.Please enter a username: fooooooooo1
Your username must contain at least one uppercase character

g.Please enter a username: Fooooooooo1
Your username is valid!

Computers and Technology
1 answer:
umka21 [38]3 years ago
3 0

Answer:

#function to validate username

def valid_username(username):

   

   #checking is length is between 8 to 15

   length_valid=True

   if(len(username)<8 or len(username)>15):

       length_valid=False;

   

   #checking is string is alphanumeric

   alphanumeric=username.isalnum()

   

   #checking first_and_last Characters of string is not digit

   first_and_last=True

   if(username[0].isdigit() or username[len(username)-1].isdigit()):

       first_and_last=False

   

   #counting uppercase lowercase and numeric Characters in string

   uppercase=0

   lowercase=0

   numeric=0

   

   for i in username:

       if(i.isdigit()):

           numeric=numeric+1

       elif(i.isalpha()):

           if(i.isupper()):

               uppercase=uppercase+1

           else:

               lowercase=lowercase+1

               

   valid_no_char=True

   if(uppercase<1 or lowercase<1 or numeric<1):

       valid_no_char=False

           

 

   #printing the result

   print("Length of username: "+str(len(username)))

   print("All Characters are alpha-numeric: "+str(alphanumeric))

   print("First and last Character are not digit: "+str(first_and_last))

   print("no of uppercase characters in the username: "+str(uppercase))

   print("no of lowercase characters in the username: "+str(lowercase))

   print("no of digits in the username: "+str(numeric))

   

   #checking string is Valid or not

   if(length_valid and alphanumeric and first_and_last and valid_no_char):

       print("Username is Valid\n")

       return True

   else:

       print("username is invalid, please try again\n")

       return False

#loop runs until valid_username enterd by user

while(True):

   

   username=input("Enter a username: ")

   if(valid_username(username)):

       break

Explanation:

The code was created by considering all the required cases asked in the question.

In this program, I asked username from the user continuously until it enters a valid username

first it check for length of string

then check is string contains only alphanumeric characters

then first and last digit is or not

than no of uppercase lowercase and numeric character

using the above parameter declare username valid or not

You might be interested in
Identify a characteristic of electronic meeting systems.
densk [106]

Answer:

The correct answer to the following question is an option (b).

Explanation:

Desktop conferencing is the feature of the electronic meeting system.

An EMS or electronic meeting system is an application that gives us the facilities of problem-solving and making decisions for that problem within a group, and it also provides the best feature of web conferencing, and the desktop conferencing by which we can chat and tells our problem in the group or a person.

8 0
4 years ago
What should the shutter speed be on the camera?<br> A. 1/30<br> B. 1/50<br> C. 1/60<br> D. 1/15
11Alexandr11 [23.1K]

Answer:

C. 1/60

Explanation:

Shutter speed is most commonly measured in fractions of a second, like 1/20 seconds or 1/10 seconds. Some high-end cameras offer shutter speeds as fast as 1/80 seconds. But, shutter speeds can extend to much longer times, generally up to 30 seconds on most cameras.

But in this case C. 1/60 is the answer.

6 0
3 years ago
It is ethical to use ICT in early years
Dahasolnce [82]
Early years of what? ICT is generally ethical as it’s just stressing unified communications of different telecommunications/IT devices
3 0
3 years ago
Which of the following is a good question to ask during an informational interview
Dmitrij [34]
The answer is:

What was your education/training path? It is related to education and information
8 0
4 years ago
Which statement best describes the role of folders in your operating system?
Naya [18.7K]
The statement that best describes the role of folders in your operating system is that Foldoers allow you to organize and maintain files (letter B).
Folders are useful for separating file types and folders are also useful for organizing programs or files on your personal computer. 
8 0
4 years ago
Other questions:
  • Implement the function calcWordFrequencies() that uses a single prompt to read a list of words (separated by spaces). Then, the
    8·1 answer
  • 1.
    8·1 answer
  • Which tab allows you to modify the width of a page margins in Microsoft word?
    7·2 answers
  • What is the Java source filename extension? What is the Java bytecode filename extension?
    14·1 answer
  • While doing online research you enter this keyword search with a truncation character: man* Which of the following would not be
    15·1 answer
  • Consider the following code:
    5·1 answer
  • Which pane in PowerPoint contains images of the slides in the order they appear in the presentation
    8·2 answers
  • Overview In this assignment, you will gain more practice with designing a program. Specifically, you will create pseudocode for
    7·1 answer
  • How has the widespread shift to remote work caused businesses to reconsider their use of Extended Reality (XR)?.
    13·1 answer
  • Different between embedded computer &amp;<br> Micro controllers
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!