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
___________ is a mass-produced, copyrighted software that meets the needs of a wide variety of users, not just a single user or
GaryK [48]

Answer: Package software

Explanation:

Packaged software is the software that contains the functions and programs that are similar in the nature and features.

It is designed in such a way so that it can attract the customers and user by providing the benefit of the selling of the collection of programs rather than buying individual software programs which costs higher.

Thus, it produced at a large scale as well as bought by numerous users.

4 0
3 years ago
What happens when you double-click one of the graphic options in the middle panel of the choose a smartart graphic dialog box?
pickupchik [31]
When you open MS Word, selecting the insert option and clicking SmartArt, will pop up SmartArt dialog box. Double-clicking on one of the graphic options in the middle panel will automatically select and place the graphic art you want. It is an easy way of inserting a SmartArt of your choice without selecting the art itself and clicking OK.





3 0
3 years ago
Read 2 more answers
Easy 25 points answer what is it called that you use only 1 and 0 like this 1010010011001100011110001010010101001010101010010101
Arlecino [84]
Binary. Is the correct answe
3 0
3 years ago
Think of an example in your life where a number could be described as data, information, and knowledge
zhannawk [14.2K]

Answer:

how many event you have been too in the last month (well non during this time but as an example)

Explanation:

4 0
3 years ago
Which item is used for formatting in responsive web design?
taurus [48]

Answer:

3) Improving image quality

Explanation:

A responsive web design is a web design that makes website to be user friendly to website users. It enables the users to have an optimal and enjoyable experience when making use of websites.

A responsive web design is the basis on which websites are built. It makes websites interactive for users such that that find the websites easy to access, easy to read and very interactive.

Computer programs used for creating a responsive web design are:

a) JavaScript

b) Cascading Style Sheets e.t.c

The item used for formatting a responsive web design is Improving Image quality. This helps to make the website responsive for users.

3 0
3 years ago
Other questions:
  • You should use html elements instead of server controls when
    11·1 answer
  • Take some time to do some research about small businesses in your area. Select one and using HTML design a simple site that educ
    11·1 answer
  • Due dates is the final date an assignment will be accepted. Plan ahead to ensure should you face difficulty with the assignment
    9·2 answers
  • It connects computers in different cities and different countries
    9·2 answers
  • What is the function of ctrl+Q​
    14·1 answer
  • A good CRM should Integrate marketing, sales, and customer support activities measuring and evaluating the process of knowledge
    13·1 answer
  • In order to be an effective employee who knows recent information on loans and laws, in what topic should your information be cu
    5·1 answer
  • What does the "zoom tool" do in Photoshop?
    15·2 answers
  • Can someone help me with this pls
    5·2 answers
  • Hello my name is Phoenix I will like for you to friend me on Ro blox my user name is Jessiahcoleman and if u play BLOX fruits or
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!