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 The Challenge

Sean Do
Sean Do
11,933 Points

Feedback on Challenge "While Loop"

Tested what I learned going through the course. Let me know what I could have done better?

https://w.trhou.se/v9hzw75tga

1 Answer

For the most part is good. Two things that caught my attention:

input("Let's test your knowledge, {}! Please enter (1, 2, 3) for the correct definition of a Python while loop. \n 1. can iterate over a sequence of numbers. \n 2. is a subset of algebra used for creating true/false statements \n 3. repeat a block of code as long as a certain Boolean condition is met.\n Entering:  ".format(name))

This is way too long and very hard to read at a quick glance. As you can see, even on this post, you have to scroll all the way to read the whole thing. You could refactor it to something more readable such as:

input("Let's test your knowledge, {}! Please enter (1, 2, 3) for the correct definition of a Python while loop. \n"
      " 1. can iterate over a sequence of numbers. \n"
      " 2. is a subset of algebra used for creating true/false statements \n"
      " 3. repeat a block of code as long as a certain Boolean condition is met.\n"
      " Entering:  ".format(name))

Or even maybe with triple quotes and a f-string (you might have not yet learned that though):

input(f"""Let's test your knowledge, {name}! Please enter (1, 2, 3) for the correct definition of a Python while loop.
 1. can iterate over a sequence of numbers.
 2. is a subset of algebra used for creating true/false statements
 3. repeat a block of code as long as a certain Boolean condition is met.
 Entering:  """)

The second thing is that in your if-else statement you are calling on both conditions understanding = question(). If it happens either way, you should remove that statement from both branches and place it below to avoid code repetition, e.g:

while question() != 3:
    if understanding == 1:
        print("Sorry that is a definition of a Python For Loop! Please try again!\n")
    elif understanding == 2:
        print("Sorry that is a definition of a Boolean! Please try again!\n")
    understanding = question()
Sean Do
Sean Do
11,933 Points

Interesting, I haven't learned input(f""""), but I like that way better. For the while loop, I knew it could have been better, but wasn't too sure when looking at it.

Thanks for the feedback!