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

Nayonna Purnell
seal-mask
.a{fill-rule:evenodd;}techdegree
Nayonna Purnell
Full Stack JavaScript Techdegree Student 6,683 Points

My code is getting an AttributeError when using .lower to start my while loop in Python, please help.

My Code is below. When I start the while loop with .lower, I get an Attribute Error: 'NoneType'. I have also written this problem with if/ else statements without .lower and got the program to work. What is wrong with my code below?

#Ask the user for their name
name = input("What's your name? ")

#Ask the user if they understand Python While loops.  
#Print the users input to the screen
comprehension = print(input(f"{name}, do you understand Python while loops?\n(Enter yes or no:)"))


#Create a while statement that checks if the user doesn't understand while loops

while comprehension.lower()== 'no':
    #If the user doesn't understand Python loops, explain them.
    print(f"Ok, {name}, while loops in Python repeat as long as a certain Boolean condition is met.")

    #Ask the user again, by name, if they understand Python loops.
    comprehension =input(print(f"{name}, now do you understand Python while loops?"))

#Outside the while loop, congratulate the user for understanding while loops.
print(f"That's great, {name}.  I'm pleased that you understand while loops now.  That was getting repetitive.")

2 Answers

Steven Parker
Steven Parker
231,268 Points

The use of "lower" seems fine, but the assignment of "comprehension" seems to have a syntax issue. The "input" statement should not be inside a "print" statement:

comprehension = input(f"{name}, do you understand Python while loops?\n(Enter yes or no:)")
Nayonna Purnell
seal-mask
.a{fill-rule:evenodd;}techdegree
Nayonna Purnell
Full Stack JavaScript Techdegree Student 6,683 Points

Thank you Steven for answering me. Why do you say that , The "input" statement should not be inside a "print" statement? Is there a rule in Python that supports your suggestion? I have used this syntax for other Python problems and it worked. Please share.

The text editor is specifically complaining about the lines below and gave an Attribute Error: 'NoneType' message.

while comprehension.lower()== 'no':
Steven Parker
Steven Parker
231,268 Points

I don't mean it can't be done, only that this "input" statement should not be inside a "print". When used here, it causes what is typed in to be put back on the screen, and more importantly it prevents the typed-in value from being stored into "comprehension" which leads to the error.