raw_input passing to fun

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

    #1

    raw_input passing to fun



    the output of this code below is not what one would expect, it outputs
    all kind of numbers and it never stops, I want to ask the user for a
    number and then print out the multiplication table up to that number.

    thanks

    *************** *************** *************** *************** ****
    import math

    def printMultiples( n, hight):
    i = 1
    while i <= hight:
    print n*i, '\t',
    i = i + 1
    print


    def printMultTable( hight):
    i = 1
    while i <= hight:
    printMultiples( i, i)
    i = i + 1

    num = raw_input ("produce a multiplication table up to: ")
    printMultTable( num)
    *************** *************** *************** *************** ****
  • John Machin

    #2
    Re: raw_input passing to fun

    On 28/04/2006 2:04 PM, Gary Wessle wrote:[color=blue]
    >
    > the output of this code below is not what one would expect, it outputs
    > all kind of numbers and it never stops, I want to ask the user for a
    > number and then print out the multiplication table up to that number.[/color]

    That's what you want, but not what you did. You asked them for a string.
    [color=blue]
    >
    > thanks
    >
    > *************** *************** *************** *************** ****
    > import math[/color]

    Not used.
    [color=blue]
    >
    > def printMultiples( n, hight):
    > i = 1
    > while i <= hight:
    > print n*i, '\t',
    > i = i + 1
    > print
    >
    >
    > def printMultTable( hight):
    > i = 1
    > while i <= hight:[/color]

    Temporarily, insert here:
    print "types:", type(i), type(hight)
    print "values:", i, hight
    if i > 100: return
    [color=blue]
    > printMultiples( i, i)
    > i = i + 1
    >
    > num = raw_input ("produce a multiplication table up to: ")
    > printMultTable( num)[/color]

    Try this: printMultTable( int(num))

    You may wish to consider changing "hight" to "height" :-)

    Comment

    • Gary Wessle

      #3
      Re: raw_input passing to fun

      John Machin <sjmachin@lexic on.net> writes:
      [color=blue]
      > On 28/04/2006 2:04 PM, Gary Wessle wrote:[color=green]
      > > the output of this code below is not what one would expect, it
      > > outputs
      > > all kind of numbers and it never stops, I want to ask the user for a
      > > number and then print out the multiplication table up to that number.[/color]
      >
      > That's what you want, but not what you did. You asked them for a string.
      >[color=green]
      > > thanks
      > > *************** *************** *************** *************** ****
      > > import math[/color]
      >
      > Not used.
      >[color=green]
      > > def printMultiples( n, hight):
      > > i = 1
      > > while i <= hight:
      > > print n*i, '\t',
      > > i = i + 1
      > > print
      > > def printMultTable( hight):
      > > i = 1
      > > while i <= hight:[/color]
      >
      > Temporarily, insert here:
      > print "types:", type(i), type(hight)
      > print "values:", i, hight
      > if i > 100: return
      >[color=green]
      > > printMultiples( i, i)
      > > i = i + 1
      > > num = raw_input ("produce a multiplication table up to: ")
      > > printMultTable( num)[/color]
      >
      > Try this: printMultTable( int(num))
      >
      > You may wish to consider changing "hight" to "height" :-)[/color]

      thank you

      Comment

      Working...