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

Angelus Miculek
Angelus Miculek
6,534 Points

triple quotes cause index errors

My code is this:

underhill = input('''{}, do you understand Python while loops?
(Enter yes/no)  '''.format(name))

while underhill.lower() != 'yes':
    underhill = input('''Ok, {}, Python while loops repeat as long as a certain Boolean condition is met.
{}, now do you understand Python while loops?
(Enter yes/no)  '''.format(name))


print("That's great, {}. I'm pleased that you understand while loops now. That was getting repeatitive.".format(name))```

3 Answers

Travis Alstrand
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Travis Alstrand
Treehouse Project Reviewer

Hiya Angelus Miculek

This is actually happening because there are two { } within that sentence it's showing in the error but only one variable to format it with provided. You'll simply need to add in name twice like so...

while underhill.lower() != 'yes':
    underhill = input('''Ok, {}, Python while loops repeat as long as a certain Boolean condition is met.
{}, now do you understand Python while loops?
(Enter yes/no)  '''.format(name, name))

In your provided code above I assumed you still had this up top

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

Things seemed to be working fine after that addition 👍

Angelus Miculek
Angelus Miculek
6,534 Points

treehouse:~/workspace$ python looping.py
What's your name? a
a, do you understand Python while loops?
(Enter yes/no) no
Traceback (most recent call last):
File "/home/treehouse/workspace/looping.py", line 18, in <module>
underhill = input('''Ok, {}, Python while loops repeat as long as a certain Boolean condition is m et.
IndexError: Replacement index 1 out of range for positional args tuple

No clue why this error happens when I say no. Is it the triple quotes?

Angelus Miculek
Angelus Miculek
6,534 Points

Thanks, Travis! You're a pro.