Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #36283 > unrolled thread

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

Started bykofi <ghanashirts4sale@gmail.com>
First post2013-01-06 12:26 -0800
Last post2013-01-06 17:01 -0500
Articles 6 — 5 participants

Back to article view | Back to comp.lang.python


Contents

  How do you call a function several times in this context?? kofi <ghanashirts4sale@gmail.com> - 2013-01-06 12:26 -0800
    Re: How do you call a function several times in this context?? Benjamin Kaplan <benjamin.kaplan@case.edu> - 2013-01-06 12:39 -0800
    Re: How do you call a function several times in this context?? Alister <alister.ware@ntlworld.com> - 2013-01-06 21:23 +0000
      Re: How do you call a function several times in this context?? Jason Friedman <jason@powerpull.net> - 2013-01-06 14:33 -0700
        Re: How do you call a function several times in this context?? Alister <alister.ware@ntlworld.com> - 2013-01-06 22:35 +0000
      Re: How do you call a function several times in this context?? Joel Goldstick <joel.goldstick@gmail.com> - 2013-01-06 17:01 -0500

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

Fromkofi <ghanashirts4sale@gmail.com>
Date2013-01-06 12:26 -0800
SubjectHow do you call a function several times in this context??
Message-ID<76529b4c-fbc7-4d6d-89a5-160545448ff2@googlegroups.com>
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: ")

[toc] | [next] | [standalone]


#36284

FromBenjamin Kaplan <benjamin.kaplan@case.edu>
Date2013-01-06 12:39 -0800
Message-ID<mailman.184.1357505147.2939.python-list@python.org>
In reply to#36283

[Multipart message — attachments visible in raw view] — view raw

On Jan 6, 2013 12:33 PM, "kofi" <ghanashirts4sale@gmail.com> 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/

[toc] | [prev] | [next] | [standalone]


#36285

FromAlister <alister.ware@ntlworld.com>
Date2013-01-06 21:23 +0000
Message-ID<oXlGs.986803$yH4.401228@fx03.am4>
In reply to#36283
On Sun, 06 Jan 2013 12:26:40 -0800, 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: ")
you need to investigate passing parameters to and from function

as you are obviously a beginner I don't want to give you the answer to 
your task but hopefully steer you in the right direction.

examine the code below & see if you can understand how it is working & 
how to apply it to your current project

def double(value):
	result
	return result

number=input('type a number')
print (double(int(number)))

this program is for explanation only and a function this simple should 
never be used in a real program, it is functionally equivalent to

number=input('type a number')
print (int(number)*2)

-- 
Alex Haley was adopted!

[toc] | [prev] | [next] | [standalone]


#36286

FromJason Friedman <jason@powerpull.net>
Date2013-01-06 14:33 -0700
Message-ID<mailman.185.1357508015.2939.python-list@python.org>
In reply to#36285
> 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

[toc] | [prev] | [next] | [standalone]


#36297

FromAlister <alister.ware@ntlworld.com>
Date2013-01-06 22:35 +0000
Message-ID<f%mGs.696422$nB6.473073@fx21.am4>
In reply to#36286
On Sun, 06 Jan 2013 14:33:26 -0700, 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

yes indeed
thanks for correcting my typo





-- 
Quigley's Law:
	Whoever has any authority over you, no matter how small, will
	atttempt to use it.

[toc] | [prev] | [next] | [standalone]


#36291

FromJoel Goldstick <joel.goldstick@gmail.com>
Date2013-01-06 17:01 -0500
Message-ID<mailman.188.1357509683.2939.python-list@python.org>
In reply to#36285

[Multipart message — attachments visible in raw view] — view raw

On Sun, Jan 6, 2013 at 4:33 PM, Jason Friedman <jason@powerpull.net> 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

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web