5 Replies - 1701 Views - Last Post: 27 March 2016 - 05:14 PM Rate Topic: -----

Poll: New to programming / New to Python. (3 member(s) have cast votes)

Python 2 or 3 for beginners?

  1. 2 (1 votes [33.33%] - View)

    Percentage of vote: 33.33%

  2. 3 (1 votes [33.33%] - View)

    Percentage of vote: 33.33%

  3. Either one, doesn't matter (1 votes [33.33%] - View)

    Percentage of vote: 33.33%

Vote Guests cannot vote

#1 cpakal  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 27-March 16

New to programming / New to Python.

Posted 27 March 2016 - 06:58 AM

Hey guys!

I am totally new to programming in the first place and to Dream in code for that matter. I've been interested in learning programming for a time and I thought about it was time for trying it out. After some research I found out Python 2.7 appeared to be a great starting language so I'm currently trying to learn that. I'm following this guide as I've never been programming before.

http://learnpythonthehardway.org/

I've done lesson 1-26. And I am currently going through them one more time before taking the test at exercise 26. But I'm having a problem at exercise 25 with functions.

http://learnpythonth.../book/ex25.html

I'm using Textwrangler to create my .py files and I've put in all the code into the file and then called it ex25.py . After that I've started my terminal and python and started to write python code into terminal but I get stuck at line 15;

ex25.print_first_and_last(sentence)



 def print_first_and_last(sentence):
    """Prints the first and last words of the sentence."""
    words = break_words(sentence)
    print_first_word(words)
    print_last_word(words) 


I had a similar problem earlier in the same exercise but I found it out as I didn't put in the code right in terminal/python. But this time i can't find the problem or why I doesn't get it to work. Could anyone please explain what I am doing wrong?

PS. What's the best way to how to programming or learning a language?

Best regards, adam!

Posted Image

Is This A Good Question/Topic? 0
  • +

Replies To: New to programming / New to Python.

#2 andrewsw  Icon User is offline

  • blow up my boots
  • member icon

Reputation: 6541
  • View blog
  • Posts: 26,484
  • Joined: 12-December 12

Re: New to programming / New to Python.

Posted 27 March 2016 - 06:59 AM

Post the error details directly here, not just within a screenshot.
Was This Post Helpful? 0
  • +
  • -

#3 cpakal  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 27-March 16

Re: New to programming / New to Python.

Posted 27 March 2016 - 07:10 AM

View Postandrewsw, on 27 March 2016 - 06:59 AM, said:

Post the error details directly here, not just within a screenshot.


Oh sorry! The error says:

>>> ex25.print_first_and_last(sentence)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "ex25.py", line 28, in print_first_and_last
    print_first_words(words)
NameError: global name 'print_first_words' is not defined

Was This Post Helpful? 0
  • +
  • -

#4 andrewsw  Icon User is offline

  • blow up my boots
  • member icon

Reputation: 6541
  • View blog
  • Posts: 26,484
  • Joined: 12-December 12

Re: New to programming / New to Python.

Posted 27 March 2016 - 07:15 AM

Quote

NameError: global name 'print_first_words' is not defined

What do you think this is telling you?

It says it cannot find a function named print_first_words.

Looking back at your screenshot, you were able to run a similarly named method earlier, called print_first_word.. Do you have a method named print_first_words?
Was This Post Helpful? 0
  • +
  • -

#5 cpakal  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 27-March 16

Re: New to programming / New to Python.

Posted 27 March 2016 - 09:55 AM

I actually had to leave my computer for a couple of hours and do something else. When I came back it was obvious after reading your comment. I must have misstyped into Textwrangler and could just not see what was wrong.

Thanks!
Was This Post Helpful? 0
  • +
  • -

#6 jon.kiparsky  Icon User is offline

  • Beginner
  • member icon


Reputation: 11022
  • View blog
  • Posts: 18,805
  • Joined: 19-March 11

Re: New to programming / New to Python.

Posted 27 March 2016 - 05:14 PM

Quote

PS. What's the best way to how to programming or learning a language?


The main thing, as with anything else, is to keep at it. There's a lot to learn, and if you stop in the middle you'll have to go back to the beginning. The next thing is to work at it every day, so you make sure you continue to build on what you learned. Then, you must always push beyond what the book says to make sure you're really understanding what lies beyond the lesson. If your book shows you an example, try to understand not just what's happening in that example, but how you can change it to make it act differently.

It's also important to understand that there's a difference between learning a programming language and learning how to write programs. Learning a language is about learning details like "in this language we use curly brackets to indicate a code block", or "in this language a for loop accesses the elements of a collection, like a list or a set, in some order, and allows you to perform some operations on them". Learning how to write programs is about learning the right way to combine these ideas to make things happen. These are quite different, and both are important.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1