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
Which query will give the following result when it it applied on table 1????!!!!!
Mandarinka [93]

Answer:

B

Explanation:

You need Name , Age and Gender

the second requirement should only match the last row where age is 20 and gender is male.

thrid requirement of the query is that its syntax should be correct.

Option B staisfies all of required so it is the correct option.

6 0
3 years ago
Question 7 (1 point)<br> Increasing hue levels means increasing saturation.<br> True<br> False
Temka [501]

Answer:

mae me brainlier

false

7 0
3 years ago
the first day anna read a quarter of the book. on the second day she read a third of the remainder. noticed that after two days
Misha Larkins [42]

Answer:

160 pages

Explanation:

Day\ 1 = \frac{1}{4}

Day\ 2 = \frac{1}{3}Remainder

Left = 80

Required

The number of pages

Let the number of pages be x.

So, on day 1; we have:

Day\ 1 = \frac{1}{4}x

After day 1, there are:\frac{3}{4}x left ----------------- i.e x - 1/4x

On day 2, we have:

Day\ 2 = \frac{1}{3} * \frac{3}{4}x

Day\ 2 = \frac{1}{4}x

At this point, we have:

Day\ 1 = \frac{1}{4}x

Day\ 2 = \frac{1}{4}x

Left = 80 ---- pages left

The summation of all must equal x, the book pages

Day\ 1 + Day\ 2 + Left = Total\\

\frac{1}{4}x + \frac{1}{4}x+ 80= x

Simplify the left-hand side

\frac{1}{2}x+ 80= x

Collect like terms

x - \frac{1}{2}x= 80

Simplify

\frac{2-1}{2}x= 80

\frac{1}{2}x= 80

Multiply by 2

2 * \frac{1}{2}x= 80*2

x = 160

4 0
3 years ago
Employers hiring for entry-level positions in Hospitality and Tourism expect workers to learn the required skills after they sta
vovikov84 [41]
<h2>have basic skills required to do the job</h2>

Explanation:

expect workers to learn the required skills after they start:  

The must have basic skills then only they can employ to upgrade further skill

have the required skills before they start:  

We cannot expect all the skills. Skill will develop through experience too.

acquire the necessary skills through education: only if they have necessary education for performing the job, then only the company will short-list. So, this is an entry criterion.

have basic skills required to do the job: This is the right answer. This aspect is enough for an entry-level position.

8 0
3 years ago
Read 2 more answers
Content controls cannot be removed, only edited. Please select the best answer from the choices provided
Anton [14]
 False is your answer
5 0
3 years ago
Other questions:
  • When technology advances which of the following always takes place?
    6·2 answers
  • What is the most important part of the course that you have learned about so far?
    11·2 answers
  • Help! I turned on my computer and this screen came on out of nowhere, I don't know what to do to fix it.
    11·2 answers
  • You want to multiply 50 in cell D3 by 8.90 in cell E3. Which formula should you use?
    11·1 answer
  • Which of the following can be considered beta testing? A programmer at Linus Systems checks the integration of multiple modules
    14·1 answer
  • 1000base-t is a standard for achieving throughputs ____ times faster than fast ethernet over copper cable.
    8·1 answer
  • I have a variable and set it equal to 5. 1 then send it as an argument to a function that adds 5 to the variable passed in. Outs
    9·1 answer
  • which statement is true? O A Future games will be more context oriented. OB. Future games will be more product driven. Future ga
    13·2 answers
  • Which of the following is not a key component of a structure?
    6·1 answer
  • Websites not only give us information, but they also inspire designers in their layouts, illustrations, images, typefaces, and c
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!