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]
2 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]2 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
What is the answer for this
tigry1 [53]

Answer:

No, not that one. Try again.

Explanation:

string comparison is case sensitive.

8 0
2 years ago
Write a program to find the product of 3 numbers
ziro4ka [17]

Answer:

#include<iostream>

using namespace std;

int main()

{

   int a,b,c;

   cout<<"enter the value of a:";

   cin>>a;

   cout<<"enter the value of b:";

   cin>>b;

   cout<<"enter the value of c:";

   cin>>c;

   cout<<"product is:"<<(a*b*c);

   return 0;

}

Explanation:

6 0
2 years ago
Read 2 more answers
Which tab is used to insert a hyperlink onto a slide
Roman55 [17]
The tab used to instead a Hyperlink into a slide is the Insert tab under the “Links” group.
5 0
2 years ago
Read 2 more answers
Save As .csv .html Worksheet tab Format Cells SUM Function Destination cell Home tab AutoFit A. Applies a border or shading to s
stiv31 [10]

Answer and Explanation:

A.) Format Cells

When the format cells in an Excel then, change an appearance of the number without the changing a number itself. Apply the number formats (0.7, $0.70, 70%, etc) or other formatting (alignments, fonts, borders, etc).

1. Enter a value 0.7 into the cell B2.

By default, the Excel use the General formats (no specific numbers format) for the numbers To apply the number format, use a 'Format Cell' dialog box.  

2. Then, Select the cell B2.

3. Then, Right click, then click the Format Cell (or press the shortcut key CTRL + 1).

The 'Format Cell' dialog box will appears.

4. Then, For example, if you want - select Currency.

Note: The Excel give you the life preview of how a number will formatted.

5. After that, Click OK.

The Cell B2 will still contain the number 0.7. Then you only changed an appearance of the number. Most frequently used a formatting command that are available on Home tab.

6. On Home tab, in a Number group, click percentage symbol to apply the Percentage formats.

7. On Home tab, in Alignment group, center a numbers.

8. On Home tab, in Font group, add the outside border and change the fonts color to the blue.

B). Destination cell

Destination area or Destination cell - A range of the cells that is select to hold a summarized data in the consolidations. The destination area or cell can be on same worksheets as source data or on the different worksheets. Worksheet can contains only the one consolidation.

C). Save As

If you want to save workbook with the different name use File then click on Save As dialog box or use a shortcut key (Alt + F2).

Then, Select a folder that you wants to store a workbook in using Save in the drop-down lists.

Then, Enters a new filename in the File name box at bottom.

D.) .html

Extension of the web page workbooks is .html.

E). SUM

The SUM function is the built in function in the excel which is used to add all the numbers in the range of the cells and returns its result.

F). Home Tab

A clipboard group is on far left side of a Home Tab. It is an often used in the conjunctions with Editing group, which is on far right side of the tab.

G.) .csv

CSV stands for Comma Separated Value.

CSV is the simple file format that is used to store a tabular datas, such as the spreadsheet or the database. A File in the CSV formats can be imported and exported from the programs that stores data in the tables, such as the Microsoft Excel or the OpenOffice Calc.

H). Worksheet tab

.

To Show the Sheet tabs settings is turned off.

Firstly, ensure that Show Sheet tab is enabled or not.

To do, all the other Excel version, click the File >then Options >then Advanced, in the under Display option for the workbook, then ensures that there is the check in a Show sheet tabs box.

I). AutoFit

J). Sum, Product, Power, Sqrt, Quotient, Mod and many others.

There are 300+ formulas in Excel.

5 0
3 years ago
Answer pls pls pls pls pls ​
nataly862011 [7]

Answer:

identify materials to create a prototype

6 0
2 years ago
Other questions:
  • Which ones are right
    15·1 answer
  • Describe the concepts of Defense in Depth and Detection in Depth. Compare and contrast. What's different? What's similar?
    9·1 answer
  • When powering off your computer is best down using?
    8·2 answers
  • How much space should be allotted to park your vehicle parallel to the curb?
    5·1 answer
  • Network a0 is a process by which several protocols evolve to form a single product.
    7·1 answer
  • If you need to define a connection request policy to apply to an 802.1x authenticating switch or a wireless access point, which
    12·1 answer
  • What is a conditional Statement that causes the program to change its course​
    11·1 answer
  • Tara is creating a presentation for her science project about volcanoes. She added different animations to every slide for empha
    12·1 answer
  • Which type of boot authentciation is more secure?
    10·1 answer
  • Which is a monthly cost associated with renting a house?
    11·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!