How do you call a function several times in this context??

Discussion in 'Python' started by kofi, Jan 6, 2013.

  1. kofi

    kofi Guest

    Using python 3.1, I have written a function called "isEvenDigit"

    Below is the code for the "isEvenDigit" function:

    def isEvenDigit():
    ste=input("Please input a single character string: ")
    li=["0","2","4", "6", "8"]
    if ste in li:
    print("True")
    else:
    print("False")

    I am now trying to write a function that takes a string as an argument and makes several calls to the isEvenDigit function in order to calculate and return the number of even digits in the string.How do i do this please? This is what i have done so far.

    def isEvenDigit2():
    number = input("Enter a digit: ")
     
    kofi, Jan 6, 2013
    #1
    1. Advertising

  2. On Jan 6, 2013 12:33 PM, "kofi" <> wrote:
    >
    > Using python 3.1, I have written a function called "isEvenDigit"
    >
    > Below is the code for the "isEvenDigit" function:
    >
    > def isEvenDigit():
    > ste=input("Please input a single character string: ")
    > li=["0","2","4", "6", "8"]
    > if ste in li:
    > print("True")
    > else:
    > print("False")
    >
    > I am now trying to write a function that takes a string as an argument

    and makes several calls to the isEvenDigit function in order to calculate
    and return the number of even digits in the string.How do i do this please?
    This is what i have done so far.
    >
    > def isEvenDigit2():
    > number = input("Enter a digit: ")


    Use a loop and call the function in the body of the loop. In this case, you
    would use a for loop iterating over number. If you don't know how to use a
    for loop, I recommend you do the tutorial at
    http://docs.python.org/3.3/tutorial/
     
    Benjamin Kaplan, Jan 6, 2013
    #2
    1. Advertising

  3. > def double(value):
    > result
    > return result
    >
    > number=input('type a number')
    > print (double(int(number)))
    >


    I think what was meant:

    def double(value):
    result = 2 * value
    return result
     
    Jason Friedman, Jan 6, 2013
    #3
  4. On Sun, Jan 6, 2013 at 4:33 PM, Jason Friedman <> wrote:

    > > def double(value):
    > > result
    > > return result
    > >
    > > number=input('type a number')
    > > print (double(int(number)))
    > >

    >
    > I think what was meant:
    >
    > def double(value):
    > result = 2 * value
    > return result
    > --
    > http://mail.python.org/mailman/listinfo/python-list
    >


    #get the string of numbers outside your function:

    is_even
    number = input("type an integer')

    #Here is some code to loop through each digit

    for n in number:
    is_even_digit(n) # this function should test the number and print what
    you want for odd and even

    #This will pass each digit to your function. I renamed your function to
    reflect better python naming conventions



    --
    Joel Goldstick
     
    Joel Goldstick, Jan 6, 2013
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?TWFyZHk=?=

    Browser Progress Bar Shows several times

    =?Utf-8?B?TWFyZHk=?=, Dec 6, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    448
    =?Utf-8?B?TWFyZHk=?=
    Dec 6, 2005
  2. Jimi Hullegård
    Replies:
    15
    Views:
    1,269
    Raymond DeCampo
    Sep 6, 2005
  3. Rahul
    Replies:
    0
    Views:
    493
    Rahul
    May 11, 2006
  4. Rahul
    Replies:
    0
    Views:
    470
    Rahul
    May 11, 2006
  5. Victor \Zverok\ Shepelev

    RDOC: several related modules in several C files

    Victor \Zverok\ Shepelev, Mar 6, 2007, in forum: Ruby
    Replies:
    3
    Views:
    185
    Max Lapshin
    Mar 16, 2007
Loading...

Share This Page