Write a program that reads a string (password) and a number. The program will keep asking the user for a password and number as long as the user does not provide the expected values ("milkyway" and 1847, respectively), and as long as the user has not exhausted the maximum number of attempts . In addition, the program will stop asking for data if the word "quit" is provided as a password value (in this case, the program will not read the number). The program will print the message "Wrong credentials" when an invalid password or number (or both) is provided. If the user eventually provides the correct credentials the message "Access Granted" will be displayed; otherwise the message "Access Denied" will be generated. The following example illustrates the messages to use to read data and to display results. Enter password: milkyway
Enter number: 10
Wrong credentials
Enter password: tomato
Enter number: 1847
Wrong credentials
Enter password: milkyway
Enter number: 1847
Access Granted

Answers

Answer 1
Answer:

Answer:

// Program is written in Java Programming Language

// Comments are used for explanatory purpose

// Program starts here

import java.util.Scanner;

public class checkPass{

public static void main (String [] args)

{

// Call scanner function

Scanner input = new Scanner (System.in);

// Declare user password and number

string userpass;

int usernum;

// Initialise password and number

string password = "milkway";

int number = 1847;

// Initialise number of attempts to 0

int attempts = 0;

while (attempts<=10 )

{

// Prompt user to enter password and number

System.out.println("Enter password: ");

userpass = input.nextLine();

System.out.println("Enter Number: ");

usernum = input.nextInt();

if(userpass == password && usernum == number)

{

System.out.print("Access Granted");

attempts = 11;

}

else

{

System.out.print("Wrong Credentials");

attempts++;

}

}

}

}

Answer 2
Answer:

Explanation:

The correct password and number are defined and stored in their respective variables. While loop is used to keep on taking input from the user until the user inputs correct password and number or user runs out of attempts. The number of attempts is set to 3 but can be changed to any number as you like.

The user is asked to input password first then we check if the user wants to quit? if true terminate program else continue to get the input number from the user.

Now we have password and number from the user, check if both are correct? if yes then grant the access else wrong credentials add one to the attempt, display the number of attempts left and repeat the whole loop again.

Python Code:

password = "milkyway"

number = 1847

attempts=0

while attempts < 3:

   pas=str(input("Please Enter the Password\n"))

   if pas=="quit":

       print("You quit!")

       break

   num=int(input("Please Enter the Number\n"))

   if pas==password and num==number:

       print("Access Granted")

   else:

       print("Wrong credentials")

       attempts+=1

       print("Attempts left: ",3-attempts)

Output:

Test 1:

Please Enter the Password

waysnf

Please Enter the Number

1847

Wrong credentials

Attempts left: 2

Please Enter the Password

milkyway

Please Enter the Number

1942

Wrong credentials

Attempts left: 1

Please Enter the Password

milkyway

Please Enter the Number

1847

Access Granted

Test 2:

Please Enter the Password

menas

Please Enter the Number

4235

Wrong credentials

Attempts left: 2

Please Enter the Password

quit

You quit!

Note: feel free to ask in comments if you dont understand anything!


Related Questions

Edhisive 3.5 code practice
Many organizations have policies that require users to: a. retain their passwords for a minimum of 30 days. b. include at least three consecutive letters of part of their name in their passwords. c. change their passwords on a regular basis. d. share their passwords with the administrator.
Which is true of diagnosing and troubleshooting? Diagnosing attempts to identify the source of a problem, while troubleshooting looks for the nature of the problem. Diagnosing is used to fix problems with hardware, while troubleshooting is used to fix problems in program code. Diagnosing looks for the nature of the problem, while troubleshooting attempts to identify the source of the problem. Diagnosing is used to fix problems in program code, while troubleshooting is used to fix problems with hardware.
When emergency changes have to be made to systems, the system software may have to be modified before changes to the requirements have been approved. Suggest a model of a pro- cess for making these modifications that will ensure that the requirements document and the system implementation do not become inconsistent.
An employee’s total weekly pay equals the hourly wage multiplied by the total number of regular hours, plus any overtime pay.Overtime pay equals the total overtime hours multiplied by 1.5 times the hourly wage.Write a program that takes as inputs the hourly wage, total regular hours, and total overtime hours and displays an employee’s total weekly pay.Below is an example of the program inputs and output:Enter the wage: $15.50Enter the regular hours: 40Enter the overtime hours: 12The total weekly pay is $899.0

Before a structure can be used, it must beA.
declared

B.
deallocated

C.
initialized

D.
All of the above

Answers

Answer:

A. declared

Explanation:

Before a structure can be used, it must be  declared.

For example:

// Structure definition

struct s{

int a;

char b;

};

// Structure instantiation

struct s  mystruct;

// This is where a structure instance called mystruct is created whose

// datatype is struct s.

mystruct.a = 10;

mystruct.b = 'c';

As we can see from the example definition precedes use for the structure.

An example of negative self-talk is:

Answers

Answer:

when you call yourself fat or ugly......but that was my answer but pls dont ever be negative abt yalls selfs i love yall the way u are and if u eva wanna talk ill do it in the comments

Explanation:

Answer:

for example, when there is a bad driver on the road near you does something dumb and the little voice in your head always says you idiot watch where you are going. It also can be when you put yourself down like saying that you are dumb or that you will never get a job

a. Business, scientific, and entertainment systems are inherently complex. It is a well-known fact that systems can be better understood by breaking them down into individual tasks. Share how a programmer would use "top-down design" to understand better how a computer program should be designed. How do hierarchy charts aid the programmer?

Answers

Answer:

Explanation:

Top-down design allows a programmer to take a complex idea, break it down into high-level tasks which can be further broken down into more detailed sub-tasks (Evans, Martin, & Poatsy, 2018). The larger a program gets, the more important it is to have a clear design. It is easier to fix an error during the design phase than the coding phase. If the design is flawed, a programmer can end up having to delete or rewrite large portions of code. Reworking large portions of a design is preferable to rewriting large portions of code. Even small programs can become overwhelming with a number of tasks to perform. Hierarchy Chart (hierarchical diagram) shows the breakdown of a system to its lowest manageable parts. It is a top-down modular design tool, constructed of rectangles (that represents the different modules in a system) and lines that connect them. The lines explain the connection and/or ownership between the different modules among the system just like in an organizational chart. main purpose is to describe the structure and hierarchy of an entity. This entity could be a strategy, event, software program, and so on. The hierarchy chart is suitable in any situation that aims to present the organized structure of a material or an abstract entity.

viewRatings(string, int) Takes a username and a minimum rating value. It prints all the books that the user has rated with a value greater than or equal to the minimum rating value. The function does not return anything.

Answers

Answer:

def ViewRatings(str, rating):

   for book in books:

       if r >= rating:

           print(book)

ViewRatings("emma", 3)

Explanation:

* The code is in Python.

Since the are missing parts in your question. I am assuming there is a books list and there is a rating, r for each book.

- Create a function called ViewRatings that takes two parameters

- Initialize a for loop that iterates through each book in the books list

- For each book, check its rating with given rating. If the rating of the book is greater than or equal to given rating, print the book

- Call the function

How do you calculate the total resistance in a series circuit with more than one resistor?

Answers

Resistors are said to be connected in series when they are daisy chained together in a single line. The serial circuit of resistors result  has a common current flowing through the resistors.
The current that flows through one resistor must also flow through the others.

The total equivalent resistance, is given as:

Rtotal = R1 + R2 + R3 , where R1 is the resistance of the first resistor, R2 of the second and R3 f the third

Which exercise can help you prevent Carpel Tunnel Syndrome?make a fist, hold, and stretch your fingers

bend slightly and stretch your right hand up

move your head back and forward slowly

blink your eyes often

Answers

Make a Fist, hold, and stretch your fingers is the correct answer
A. make a fist, hold, and stretch your fingers

C And D are rather absurd as Carpal Tunnel Syndrome is 
caused by a pinched nerve in the wrist.