Java Java Basics Perfecting the Prototype Looping until the value passes

Ali Abadi
Ali Abadi
2,885 Points

Need help with this do while loop question on python

Having trouble with this last part of the task. It's asking me to print a piece of text using the console.printf function when the user responds with yes.

Example.java
// I have initialized a java.io.Console for you. It is in a variable named console.
String response;
boolean isInvalidWord;
do {
  response = console.readLine("Do you understand do while loops?  ");
  isInvalidWord = (response.equalsIgnoreCase("no"));
  if (isInvalidWord) {
    console.printf("Go and learn about them. They're really useful!");
  }
} while(isInvalidWord);
if (response == ("yes")) {
    console.printf("Because you said {}, you passed the test!".format(response));
  }

1 Answer

Steven Parker
Steven Parker
201,915 Points

It looks like you're mixing the syntax of different languages.

You mentioned "python" in the question title, but this is the Java topic group, and this code is (mostly) Java. But for the last task, you used the syntax for the Python formatting function in a call to Java's "printf". Java doesn't use the "format" function and the substitution tokens in a Java "printf" are different from the ones used in Python.

Also, the instructions didn't say to only output the final string if the result was "yes". It should be done when the answer is anything other than "No".