Formatted Input

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Deep

    #1

    Formatted Input

    Hi all,
    I am a newbie to python
    I have an input of form
    <one numberspace <another number>
    ie.
    4 3
    how can i assign these numbers to my variables??

  • Dan Bishop

    #2
    Re: Formatted Input

    On Mar 10, 1:29 pm, "Deep" <deepblue...@gm ail.comwrote:
    Hi all,
    I am a newbie to python
    I have an input of form
    <one numberspace <another number>
    ie.
    4 3
    how can i assign these numbers to my variables??
    n1, n2 = map(int, raw_input().spl it())

    Comment

    • Larry Bates

      #3
      Re: Formatted Input

      Deep wrote:
      Hi all,
      I am a newbie to python
      I have an input of form
      <one numberspace <another number>
      ie.
      4 3
      how can i assign these numbers to my variables??
      >
      Or with list comprehension:

      n1, n2 = [int(n) for n in raw_input().spl it()]

      Neither of these methods checks for errors (e.g. non-integers)

      -Larry

      Comment

      Working...