Results 1 to 7 of 7

Thread: Very Basic Question about Python

  1. #1
    Join Date
    Jul 2011
    Beans
    15

    Very Basic Question about Python

    I am new to Python and programming in general and just had a very basic question that I can't seem to find the answer for anywhere. I am using IDLE to enter my Python code. Prior to this I was just using the Terminal to do so. What I can't seem to figure out is how to enter multiple lines of code before output is given. For instance if I say:

    print "Line One" #I Get
    Line One
    print "Line Two" #I Get
    Line Two

    How exactly do I write this so that it produces both outputs at one time? Like for instance this:

    print "Line One"
    print "Line Two"

    Line One
    Line Two

    I know that's probably a basic questions but the books I have been reading and my recent searches haven't seemed to yield any results. Thanks a lot for your time!

  2. #2
    Join Date
    Dec 2008
    Location
    Deep Woods of PA
    Beans
    699
    Distro
    Kubuntu 11.10 Oneiric Ocelot

    Re: Very Basic Question about Python

    Quote Originally Posted by Lestathim View Post
    I am new to Python and programming in general and just had a very basic question that I can't seem to find the answer for anywhere. I am using IDLE to enter my Python code. Prior to this I was just using the Terminal to do so. What I can't seem to figure out is how to enter multiple lines of code before output is given. For instance if I say:

    print "Line One" #I Get
    Line One
    print "Line Two" #I Get
    Line Two

    How exactly do I write this so that it produces both outputs at one time? Like for instance this:

    print "Line One"
    print "Line Two"

    Line One
    Line Two

    I know that's probably a basic questions but the books I have been reading and my recent searches haven't seemed to yield any results. Thanks a lot for your time!
    Code:
    print "Line One\nLine Two\n"
    Regards,

    Karlson

  3. #3
    Join Date
    Mar 2010
    Location
    Norway
    Beans
    674

    Re: Very Basic Question about Python

    Code:
    print "Hello,"; print "Mars!"
    Pythons executes the same way in IDLE as it does with a text file, one line at a time. But when it's in a text file, python know what the next line is.

  4. #4
    Join Date
    Jul 2011
    Beans
    15

    Re: Very Basic Question about Python

    Thanks a lot for the help guys. That answers part of my question I'd say but it kinda raises another. The book I'm reading "How to Think Like a Computer Scientist" (heres a link to the book http://www.greenteapress.com/thinkpy.../thinkCSpy.pdf), has a part in it, on the bottom page 27, that has the user, after defining to make a new blank line, write this:


    print "First Line."
    newLine()
    print "Second Line.

    and in turn gets this:

    First line.

    Second line.

    When I write it this is what happens:

    print "First Line."
    First Line
    newLine()

    print "Second Line"
    Second Line

    So what I'm essentially do is entering some input, getting some output. What I want to do is enter all of the input just like they did in the book, and get all of the output. What I can't seem to do is just that. I hope I'm explaining myself clearly enough, if not I apologize. Anyway, thanks again for your time guys.

  5. #5
    Join Date
    Jan 2008
    Location
    Lausanne, Switzerland
    Beans
    341
    Distro
    Ubuntu 13.04 Raring Ringtail

    Re: Very Basic Question about Python

    In IDLE, use the menu File > New Window. In that new window, you can type a program of several lines. Save the file then press F5 to run it.

  6. #6
    Join Date
    Nov 2005
    Location
    Sendai, Japan
    Beans
    11,296
    Distro
    Kubuntu

    Re: Very Basic Question about Python

    Notice how there is no ">>>" before the input, this not done through the interpreter. You must write the lines in a text file, save it as something.py and run it with

    Code:
    python something.py

  7. #7
    Join Date
    Jul 2011
    Beans
    15

    Re: Very Basic Question about Python

    Oh Oh Oh I understand! Wow thanks so much for your help everyone. I really appreciate it. That all makes complete sense now. Thanks again!

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •