[Tutor] Re: Hello new to python and the mailing list, need some help

K J game at gameweave.com
Sun May 30 15:31:27 EDT 2004


Ya that helped alot! thanks. I see that I can also put the 3 print lines in to one ie: print line_a, line_b, line_c and it outputs the same thing. 

    I must say this is the funnest programming language that I have ever had the pleasure of teaching my self.

Kevin
  ----- Original Message ----- 
  From: Nick Lunt 
  To: K J ; tutor at python.org 
  Sent: Sunday, May 30, 2004 2:46 PM
  Subject: RE: [Tutor] Re: Hello new to python and the mailing list, need some help


  Hi Kevin,

  you can stop python appending its own newline with a comma,

  ie

  print line_a,
  print line_b,

  etc.

  Hope that helps
  Nick



    -----Original Message-----
    From: tutor-bounces at python.org [mailto:tutor-bounces at python.org]On Behalf Of K J
    Sent: 30 May 2004 19:13
    To: tutor at python.org
    Subject: [Tutor] Re: Hello new to python and the mailing list, need some help


    Thank you to all that help me on that. I got it to write seperate lines with
    out useing any loops. Thanks for telling my about the upper case thing I did
    not know that. Here is the code I made:

    name = raw_input("What is your name? ")
    age = raw_input ("What is your age? ")
    sex = raw_input ("What is your sex? ")

    player = open("name.plr", 'w')
    player.write (name+'\n')
    player.write (age+'\n')
    player.write (sex+'\n')
    player.close()

    player = open("name.plr", 'r')
    line_a = player.readline()
    line_b = player.readline()
    line_c = player.readline()
    player.close()

    print line_a
    print line_b
    print line_c

    The output is like this
    Kevin

    27

    Male

    Is there a way to bring the lines closer to gether? Sorry for all the
    questions I still have not had time to go buy a Python book, I have only
    been reading what I can on the internet and most of the tutorials don't
    explain this stuff.
    Thanks again,

    Kevin
    ----- Original Message -----
    From: "Alan Gauld" <alan.gauld at blueyonder.co.uk>
    To: "K J" <game at gameweave.com>; <tutor at python.org>
    Sent: Sunday, May 30, 2004 12:49 PM
    Subject: Re: [Tutor] Hello new to python and the mailing list, need some
    help


    > Hi Kevin, welcome to Python.
    >
    > There are several points to mke, only one of which
    > actually resolves your problem :-)
    >
    > > ...I want to write to a seperate line so that it will
    > > print on the screen like this:
    >
    > > here is the code that I did:
    > > NAME = raw_input("What is your name? ")
    > > AGE = raw_input ("What is your age? ")
    > > SEX = raw_input ("What is your sex? ")
    >
    > First, by convention all uppercase letters are usually
    > reserved for fixed values or constants. Its just a convention
    > but a pretty well respected one. A mnore normal convention
    > for variable names is to keep then lower case and capitalize
    > any secondary words within the name., like this:
    >
    > aLongName
    >
    > It doesn't change how the code works but makes it easier
    > for other people to read your code.
    >
    > > player = open("name.plr", 'w')
    > > player.write (NAME)
    >
    > You are writing the data but the data has no newline at the end.
    > You need to add it. Unfortunately python files have a readline()
    > method but no writeline() - for reasons which have always puzzled me!
    >
    > To add the newline we use the character sequence:
    >
    > '\n'
    >
    > so to write to the file you need to do:
    >
    > player.write(NAME+'\n')
    >
    > > player = open("name.plr", 'r')
    > > line = player.readline()
    > > player.close()
    >
    > This will only read one line of input, if you need to read the
    > others you will either have to add multiple lines like the above
    > or use a loop - which you may not have come across yet in whatever
    > tutor you are following!
    >
    > HTH,
    >
    > Alan G
    > Author of the Learn to Program web tutor
    > http://www.freenetpages.co.uk/hp/alan.gauld/tutor2
    >
    >
    >
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20040530/8d3335cf/attachment-0001.html


More information about the Tutor mailing list