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
VARVARA [1.3K]
3 years ago
6

Write a function named enterNewPassword. This function takes no parameters. It prompts the user to enter a password until the en

tered password has between 8 and 15 characters, including at least one digit. Tell the user whenever a password fails one or both of these tests. The function enterNewPasswordshould return the new password.
Computers and Technology
1 answer:
zloy xaker [14]3 years ago
4 0

Answer:

def enterNewPassword():

 while True:

   password = input("Enter password: ")

   has_digit = False

   for i in password:

     if i.isdigit():

       has_digit = True

       break

   

   if not has_digit or (len(password) < 8 or len(password) > 15):

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

       print("The password length must be between 8 and 15!")

     if not has_digit:

       print("The password must include at least one digit!")

   else:

     return password

print(enterNewPassword())

Explanation:

*The code is in Python.

Create a function named enterNewPassword that takes no parameter

Create an indefinite while loop. Inside the loop, ask the user to enter the password. Initialize the has_digit as False, this will be used to check if password contains a digit or not. Create a for loop, that that iterates through the password, if one character is digit, set the has_digit as True and stop the loop (Use isdigit() to check if the character is digit or not).

After the for loop, check if has_digit is false or the length of the password is not between 8 and 15. If the length of the password is not between 8 and 15, print the error. If has_digit is false, again print the error.

Otherwise, password met the requirements and return the password

Call the enterNewPassword() function and print the result

You might be interested in
Given the string variable address, write an expression that returns the position of the first occurrence of the string avenue in
Delicious77 [7]
It depends on a language you code. I think this could be either C++ or Java. I know answer for both of them.
For C++:  <span>address.find("Avenue")
For Java: </span><span>address.indexOf("Avenue")</span>
4 0
3 years ago
What should you do if your temperature gauge moves up to just below the red zone?
Alexeev081 [22]
<span>If the temperature gauge moves up to just below the red zone,you should turn off your air conditioner and turn on your vehicle's heater. Then immediately </span>find a mechanic or pull over safely and contact a road service.




4 0
3 years ago
Read 2 more answers
Which single OSPF network statement will correctly include all the interfaces on a device whose IP addresses only begin with a 1
tester [92]

Answer:

network 10.10.8.0 0.0.3.255 area 0

this will include all the interfaces on a device whose IP addresses only begin with a 10.10.8, 10.10.9, 10.10.10, or 10.10.11.

Explanation:

<em>show ip ospf interface </em>

<em>show ip ospf interface brief</em>

these commands are used to display the interfaces that have been enabled into local ospf . it also shows explanation about them by brief command mentioned above.

<em />

4 0
3 years ago
Write a program that reads in the following data, all entered on one line with at least one space separating them: a) an integer
Rina8888 [55]

Answer:

import java.util.Scanner;

public class DataConstraint {

public static void main(String[] args) {

System.out.print("Enter month, day, year separated by spaces :");

Scanner sc=new Scanner(System.in);

int M,D,Y;

M=sc.nextInt();

D=sc.nextInt();

Y=sc.nextInt();

if(1<=M && M<=12 && 1<=D && D<=31 && Y>=1)

{

if(M==4 || M==6 ||M==9 || M==11){

if(D==31) {

System.out.println("month "+M+" can not have more than 30 days");

System.exit(0);

}

}

else if(M==2)

{

if((Y%400==0) || (Y%4==0 && Y%100!=0)) {

if(D>=30) {

System.out.println("month "+M+" cannot have "+D+" days");

System.exit(0);

}

}

else {

if(D>=29) {

System.out.println(Y+" is not a leap year, "+D+" is invalid");

System.exit(0);

}

}

}

System.out.println(M+" "+D+" "+Y+" is a valid date");

}

else{

if(1>=M || M>=12) System.out.println(M+" is not a valid month");

if(1>=D || D>=31) System.out.println(D+" is not a valid date");

if(Y<1) System.out.println("year can not be negative");

}

}

}

Explanation:

  • Use a conditional statement to check the month is between 1 and 12.
  • Check that the date is between 1 and 31 and year must be positive value.
  • If no. of days are more than 29, then the year cannot be a leap year.

4 0
3 years ago
Matching parentheses. An math expression may have a number of parentheses like (, ), [, ], { and }. Each openning parenthesis (,
Solnce55 [7]
C++ Code

#include
using namespace std;

bool match(const char exp[],const int s)
{
// declare a character array to perform stack operations
char stack[s];

// declare top and initialize to -1 and flag to 0
int top=-1,i,flag=0;

// visit all characters in the expression string
for(i=0;i {
// if the character is [ or ( or { then push it into stack
if(exp[i]=='[' || exp[i]=='(' || exp[i]=='{')
{
top++;
stack[top]=exp[i];
}
// if the character is ] or ) or } then check conditions
else if(exp[i]==']' || exp[i]==')' || exp[i]=='}')
{
// check stack is empty or not
if(top!=-1)
{
// check all possible failure conditions
if(exp[i]==')' && (stack[top] == '{' || stack[top]=='['))
{
flag = 1;
break;
}
else if(exp[i]==']' && (stack[top] == '{' || stack[top]=='('))
{
flag = 1;
break;
}
else if(exp[i]=='}' && (stack[top] == '(' || stack[top]=='['))
{
flag = 1;
break;
}
top--;
}
else
{
flag=1;
break;
}
}
}
// after visiting all characters of expression string check if stack is not empty and flag is 1. if any one of the condition is true return false. otherwise return true

if(top>=0 || flag==1)
return false;
else
return true;
}

int main()
{

// declare character array to store expression
char exp[10000];
cout<<"Enter an Expression"<
// read expression from user
cin.getline(exp, 10000);
int s=0;

// find the length of the expression string
for(int i=0;exp[i]!='\0';i++)
{
s++;
}

// call the match function
bool status = match(exp,s);

// print the result based on value returned by match() function
if(status == 1)
cout<<"true"< else
cout<<"false"<
}


Sample Input/Output is attached

3 0
2 years ago
Other questions:
  • When pasting an object which has been copied from a different slide, where on the slide does the object paste, assuming nothing
    15·1 answer
  • When parking ur vehicle facing downhill with a curb, you should point ur front wheels?
    7·2 answers
  • Which of the following are examples of software? Check all of the boxes that apply.
    12·2 answers
  • Which device or software application detects errors in system configurations?
    8·1 answer
  • Which is the best and quickest way for Jim to share his scuba experience with everyone?
    8·1 answer
  • If you have a charger that’s not from Apple, then could that damaged your iPhone or not?
    5·1 answer
  • Quinton is having trouble learning Spanish because he keeps reverting back to the grammatical structures of his native English l
    6·1 answer
  • What is income?
    10·2 answers
  • Whats the correct answer
    15·2 answers
  • PLEASE HELP!
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!