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

Python Challenge Solution

Is there an easier way to come to this answer?

This was the exact solution that I implemented. What really gave me trouble during this exercise was me trying to find a correct answer in less lines of code. Is there a perfect way to write this line of code?

or is this the best way:

name = input("What's your name?: ")

question = input(f"{name}, do you understand while loops?: ")

while question.lower() != "yes": print(f"{name}, While loops check if something is true or not and execute a line of code until it is") question = input(f"{name}, do you understand while loops? ")

print("Congratulations on understanding while loops!!!")

2 Answers

John Sns
John Sns
4,193 Points

'''python

name, question = [input("What is your name?: "),input("What is your question?: ")]

print("Name: {}\nQuestion: {}".format(name,question))

'''

You can do something like this to take the input. you can use the same f"" to pass in arguments to print. Using format is just a different way.

What about this solution, is It ok ?


import sys name = input("What's your name? ")

understand_loops = input("{}, do you understand Pyhton while loops ?\n(Enter yes/no).".format(name)) while understand_loops == "no": print("ok {}, while loops in Python repeat as long as a certain Boolean condition is met\n".format(name)) try_again = input('now do you understand Python loop ?\n.(Enter yes/no).') if try_again == "yes": print('Congratulations {}, with understanding while loop in Python'.format(name)) sys.exit()