Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Basics Types and Branching If, Else and Elif

f-string error on line 5 but no line 3 or 8.

I am attempting to make my own if, elif, else statement.

Here is the code that I have written. https://github.com/M3SHack/_____SNDBX/commit/f262d4de8d9be2c1662365337c8ab01624e5cf3e

Here is the error that I am getting. https://prnt.sc/w3cr76

If I remove the f-string from line 5 the error goes away. Is there a reason why the f-strings on lines 3 and 8 do not throw errors?

PS any tips on how I could better ask this question and how I should include my research to help you all is welcomed.

Cheers.

Mel Rumsey
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Mel Rumsey
Treehouse Staff

Hey m3shack! I tried to open up your github link to check out your code but I am getting a 404 error.

I copied your code down into my VSCode and everything seems to be running fine:

who_are_you = input("What is your name? ")
if who_are_you == "Patty Wack":
    print(f"Hiya {who_are_you} do you know Nick Nack?")
elif who_are_you == "I'm new":
    print(f"Glad you decided to stop by {who_are_you} Please come in.")
else:
    print("What is your name again?")
print(f"It's nice to meet you {who_are_you}.")

Getting this output: What is your name? Mel What is your name again? It's nice to meet you Mel.

Maybe try closing your vs code and reopening it. That has solved many of my issues. The code works on my end :) Hopefully that helps! If not, try to reshare your github link and I will check it out :)

Mel,

I was able to change the repo to public. Additionally, I closed and reopened VSCode the error was still there.

who_are_you = input("What is your name? ")
if who_are_you == "Patty Wack":
    print(f"Hiya {who_are_you} do you know Nick Nack?")
elif who_are_you == "I'm new":
"""@[Mel Rumsey](https://teamtreehouse.com/melrumsey) I tried using the .format instead of f"sometext" 
and the error went away but did not print the expected response."""
    print("Glad you decided to stop by {}.format(who_are_you) Please come in.")
else:
    print("What is your name again?")
print(f"It's nice to meet you {who_are_you}.")

2 Answers

Mel Rumsey
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree seal-36
Mel Rumsey
Treehouse Staff

Oh I see the issue! I opened your github to look at your code and it looks like you are missing an underscore in your variable name on line 5 :)

   print(f"Glad you decided to stop by {who_are you} Please come in.")

That should solve your issue!

Wow. So this is what I have to look forward to in programming? :) I appreciate your help.

Mel Rumsey
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Mel Rumsey
Treehouse Staff

Lol, These issues happen all the time! Having another set of eyes on it always helps! Even the best programmers in the world experience typos regularly. :P

Keep on trekkin', coder 🖖