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 Python Basics Meet Python Variables

Pitrov Secondary
Pitrov Secondary
5,121 Points

When I tried this on VScode, it didn't work

when I run the code in VS code it says ('ada', 'is learning python') I do not understand why, when I copied the code to workspace it worked like in the video. What is the problem?

11 Answers

Just remove the triple quotes and your code should be working fine now.

Here's how I setup my VS Code for python development:

  1. Install python, choose the installer based on your computer
  2. Install python extension for VS Code (https://marketplace.visualstudio.com/items?itemName=ms-python.python)
  3. Setup the environment (https://code.visualstudio.com/docs/languages/python#_environments)

Python in Visual Studio Code

Hope it helps

Hi, did you get it sorted out? Post your code so I can help you check it out.

Pitrov Secondary
Pitrov Secondary
5,121 Points

No I still have the problem. It says: NameError: name '[the word i entered]' is not defined. but if I write in ' ' it works fine. I do not know how to I can link my VS-Code file so that you can see it, so I copied it to workspace, and then I made a snapshot of it. The code does work in Workspace, but it does not work on my VS-Code. Do you use VS-Code, so that you can copy it there and check it? Do I have to do something to VS-Code settings or something, to make it work, or how do I make it work?

Thank you that you reply!

I'm using VS-Code and the code is working fine on my side, both with single or double quotes. How about try to post your code here first. Pedraig Leoghain explained how to do that.

Podrig Leoghain
Podrig Leoghain
5,094 Points

Please post your code using the Markdown Cheatsheet for reference

Code Wrap your code with 3 backticks (```) on the line before and after. If you specify the language after the first set of >backticks, that'll help us with syntax highlighting.

Once you've copy/pasted your code into the reply, including the 3 backticks before and 3 backticks after your code and checking with the preview button (the little eye button on the right of the reply box) to make sure it is correct, we can have a look and try to help you out <3

Pitrov Secondary
Pitrov Secondary
5,121 Points

Oops, sorry i forgot to paste the code. Do I have to do it like this:

 '''first_name = input('What is your first name?            ')
print(first_name)


print('Hello, '+ first_name)

if first_name == 'Craig':
    print(first_name+' learning python ')

elif first_name == 'Boy':
print(first_name + 'is really good at learning python. Me too! ')

else:
    #finding out how old the user is
    age = int(input('How old are you ' + first_name + '?         '))

    if age <= 6:
        print('You should learn to read '+ first_name+'!!')
    if age >= 6:
        print('You are on a great age to learn Python ' + first_name)
print('Have a great day '+first_name + '!' )'''
Podrig Leoghain
Podrig Leoghain
5,094 Points

Leave out the single quotes ''' next time but yes, you must have used the backtick ```

Podrig Leoghain
Podrig Leoghain
5,094 Points

Try

print(first_name, "has come from learning JS where they use the + convention rather than commas <3 ")

p.s. use backtick which is on the tilde key (top left of your keyboard usually)

Uhm... concatenation is supported in Python right? I'm not sure that's the problem

Podrig Leoghain
Podrig Leoghain
5,094 Points

To concatenate you'll need a space between the + and the )

Thanks for pointing that out Samuel, added answer with that.

I tried your code in VS Code and it works fine. Is your current code exactly the same with the code you posted? If so, you missing the indentation for the print statement in elif block.

What about you post the error message here. It should tell us the line number of the error.

Podrig Leoghain
Podrig Leoghain
5,094 Points

To concatenate you'll need a space between the + and the )

Pitrov Secondary
Pitrov Secondary
5,121 Points

Here's what I am : https://prnt.sc/l07gon Sorry for the bad quality. I showed the problems I am facing in the terminal. Check if maybe there is something wrong with my editor. Thanks Padraig Leoghain and Samuels Zhen!

Podrig Leoghain
Podrig Leoghain
5,094 Points
  1. Why is there extra code in that file? And what are the triple quotes around that extra code for?

  2. Comment out or get rid of the excess code, leaving only the 2 lines that are needed. Do not put quotes around your input answer when you run the script. Only write Dskellth not "Dskellth".

  3. If you still get an incorrect response or errors, paste the code back into here using ``` on the line before and on the line after the code. else mark an answer as correct ;)

Pitrov Secondary
Pitrov Secondary
5,121 Points

Hmmm. Wierd... Somehow it works now. I always wrote: python [path to the file]. But I had to write /usr/bin/python3.6 [path to the file]. The way I found it out was. I went to the links that Smauel Zhen linked to, and there it said that I can run my code my right-clicking then Run Python File in Terminal, and when I did it, it automatically wrote down: /usr/bin/python3.6 [path]. I wrote my name, and it worked! Do you know why I have to write /usr/bin/python3.6?

Thank you both so much! I wouldn't have figured it out without you!

Podrig Leoghain
Podrig Leoghain
5,094 Points

Try changing the ENVIRONMENT variable on your system to use python3 rather than python2 (If you're on linux I could help further but I'm guessing you're mac or microsoft)

Pitrov Secondary
Pitrov Secondary
5,121 Points

Padraig Leoghain, I am on Ubuntu Linux.

Podrig Leoghain
Podrig Leoghain
5,094 Points

I can't remember how to do it at the moment, but they have an awesome community over at Ubuntu forums. Just search for change default python environment and you should get some relevant stuff. Have fun!