0

This is my first program ever written in Python. I'm following a guide on youtube and I've done exactly the same as the guy in the video. Here's my code:

print("hello world")
myName = input ('what is your name')
print(myName)

It doesn't work I'm getting name "something" is not defined. The guide I'm following can be found here: https://youtu.be/hFhiV5X5QM4?t=5m7s

Wayne Werner
  • 49,299
  • 29
  • 200
  • 290
SteffenCH
  • 154
  • 11

2 Answers2

0

Python 2

Input evaluates what you type in. If you type in something, it will treat it as variable.

You should either type it with quotations "something", use raw_input or switch to Python 3.

Python 3

raw_input is removed and input's functionality is same as raw_input was in Python 2, so your code should work fine.

Božo Stojković
  • 2,893
  • 1
  • 27
  • 52
  • oh yeah ive tried with quotations also but that diddnt work either also it works for the guy in the video with the same code – SteffenCH Jul 17 '16 at 19:49
  • 1
    Only in Python2. The tutorial video is definitely Python3 – Wayne Werner Jul 17 '16 at 19:49
  • Ah, haven't checked the video. The brackets for print don't signify that it is indeed version 2, as it is supported syntax. – Božo Stojković Jul 17 '16 at 19:51
  • The behavior of the program in the video verify that it's Python3. At the *very* least you should be pointing out that there is a difference between Python2 and Python3, rather than just making a blanket statement. – Wayne Werner Jul 17 '16 at 19:53
  • Arh well that makes sence then i guess thanks! – SteffenCH Jul 17 '16 at 19:53
  • @WayneWerner Yeah, I was asuming the problem was in using `input` and not in python version. It was odd to me that `input` wouldn't work in this manner in python 3, so I assumed it was python 2. Thanks for pointing that out. – Božo Stojković Jul 17 '16 at 19:55
0

The code you're using was probably written with Python 3, and you're probably running Python 2.

As @Slayther points out, in Python 2, you should be using raw_input instead of input. (If you're just getting started, though, I would recommend just using Python 3!)

user94559
  • 59,196
  • 6
  • 103
  • 103
  • How do i change from 2.7 to 3 ? im useing visual studio and i have both versions installed, btw thanks for the answer i aint high enougth reputation to mark as answer tho – SteffenCH Jul 17 '16 at 19:53
  • @SteffenCH you don't need rep to mark as an answer, you just need to ask a question. Why do you think you don't have enough rep to mark an answer? Upvoting (the uparrow) is not marking an answer - the check mark marks the answer – Wayne Werner Jul 17 '16 at 19:54
  • Any reputation can mark answer as accepted. Just click the tick on the left side of the answer. – Božo Stojković Jul 17 '16 at 19:54
  • @SteffenCH Unfortunately, I've never used Python with Visual Studio, so I'm not sure how to tell it which Python to use. :-( Maybe ask a separate question for that? – user94559 Jul 17 '16 at 19:55
  • Actualy i just figured it out thanks alot guys, any tips on how to get started with python ? i come from basic stuffs in VB.NET C# and ive done a bit of database stuff ( just so u know where im standing ) – SteffenCH Jul 17 '16 at 19:57
  • @SteffenCH if searching google for "Visual studio change python version" doesn't provide a reasonable result in the top 10, I would definitely go ahead and ask another question. – Wayne Werner Jul 17 '16 at 19:57
  • @SteffenCH follow the [official python tutorial](https://docs.python.org/3/tutorial/) Once you get a few more rep here on SO you can join us in the [python chat room](http://chat.stackoverflow.com/rooms/6/python) and we'll be happy to c̶o̶r̶r̶u̶p̶t̶ mold you ;) – Wayne Werner Jul 17 '16 at 20:00
  • Great thanks see you in there haha – SteffenCH Jul 17 '16 at 20:02