Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Mac Terminal
#1
I'm using a Udemy tutorial to learn Python3. From my Mac Terminal, I start Python3 but continue to get NameErrors when trying to do something simple like create a variable. The only thing that seems to work is standard python commands. See attached for an example. This is driving me crazy and I can't seem to find any solution to what the problem may be. Help!

Last login: Sat Jul 14 00:07:20 on ttys001
MacBook-Pro:~ cstevenson$ echo $PATH
/Library/Frameworks/Python.framework/Versions/3.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
prolificss-MacBook-Pro:~ cstevenson$ python3
Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 26 2018, 23:26:24) 
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> print(goodness)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'goodness' is not defined
>>> c = cats
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'cats' is not defined
>>>
Reply
#2
it looks you don't understand what variable is

in your example goodness is variable name. However before you try to print it you nave defined it (i.e. give some value to it).
Python 3.5.2 (default, Nov 23 2017, 16:37:01) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> goodness = 'This is my goodnes variable value'
>>> print(goodness)
This is my goodnes variable value
>>> print('goodness')
goodness
>>> 
in the second print note the quotes around goodness

that is what you try to do with c variable
>>> c = 'cats'
>>> c
'cats'
in the interpreter you can just show variable values like this
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
Thank you and apologies for the rookie mistake on posting. Will heed your direction.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020