Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > How do you call a function several times in this context??

Reply
Thread Tools

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

 
 
kofi
Guest
Posts: n/a
 
      01-06-2013
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: ")
 
Reply With Quote
 
 
 
 
Benjamin Kaplan
Guest
Posts: n/a
 
      01-06-2013
On Jan 6, 2013 12:33 PM, "kofi" <(E-Mail Removed)> 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/

 
Reply With Quote
 
 
 
 
Jason Friedman
Guest
Posts: n/a
 
      01-06-2013
> 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
 
Reply With Quote
 
Joel Goldstick
Guest
Posts: n/a
 
      01-06-2013
On Sun, Jan 6, 2013 at 4:33 PM, Jason Friedman <(E-Mail Removed)> 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
RDOC: several related modules in several C files Victor \Zverok\ Shepelev Ruby 3 03-16-2007 04:15 PM
Browser Progress Bar Shows several times =?Utf-8?B?TWFyZHk=?= ASP .Net 2 12-06-2005 12:16 PM
write a function such that when ever i call this function in some other function .it should give me tha data type and value of calling function parameter komal C++ 6 01-25-2005 11:13 AM
Losing wireless connection several times a day =?Utf-8?B?YnJpZGdhcnc=?= Wireless Networking 4 12-04-2004 08:54 PM



Advertisments