[Tutor] inputting strings into functions

Paul Jones paulnsharon@dingoblue.net.au
Thu, 15 Mar 2001 16:29:27 +1000


This is a multi-part message in MIME format.

------=_NextPart_000_003A_01C0AD6D.1A508920
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

I just figured out how to make it work- sorry if anyone has already =
worked on it.
the program below works when I input the parameters as strings.=20

def countletters(string,letter):
 fruit =3D string
 count=3D0
 index=3D0
 for char in fruit:
  if char =3D=3D letter:
   count=3Dcount+1
 print count

=20
>>> countletters("monsterio","o")
2
>>> countletters('monsterio','e')
1

I'm still not sure why I can't just declare the parameters as strings in =
the function definition and then just input them without quotes into the =
function parameters when I call the function.
Regards..
Paul Jones
email: paulnsharon@dingoblue.net.au

------=_NextPart_000_003A_01C0AD6D.1A508920
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 5.50.4134.600" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>I just figured out how to make it work- =
sorry if=20
anyone has already worked on it.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>the program below works when I input =
the parameters=20
as strings. </FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>def =
countletters(string,letter):<BR>&nbsp;fruit =3D=20
string<BR>&nbsp;count=3D0<BR>&nbsp;index=3D0<BR>&nbsp;for char in=20
fruit:<BR>&nbsp;&nbsp;if char =3D=3D=20
letter:<BR>&nbsp;&nbsp;&nbsp;count=3Dcount+1<BR>&nbsp;print =
count</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;<BR>&gt;&gt;&gt;=20
countletters("monsterio","o")<BR>2<BR>&gt;&gt;&gt;=20
countletters('monsterio','e')<BR>1</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I'm still not sure why I can't just =
declare the=20
parameters as strings in the function definition and then just input =
them=20
without quotes into the function parameters when I call the=20
function.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Regards..</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Paul Jones<BR>email: <A=20
href=3D"mailto:paulnsharon@dingoblue.net.au">paulnsharon@dingoblue.net.au=
</A></FONT></DIV></BODY></HTML>

------=_NextPart_000_003A_01C0AD6D.1A508920--