Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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
230,230 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".