[Tutor] silly question

Alan Gauld alan.gauld at freenet.co.uk
Thu Dec 23 09:29:52 CET 2004


> sorry everyone, I figured it out on my own ;)

So having made it a tutor topic, please close the discussion
by telling us what was wrong. That way the rest of us don't
spend the rest of the day worrying about it, saying
"I wonder what Jason did wrong?" :-)

Sorry if I appear to nag but its how these mailing lists
work - someone posts a problem, everyone looks at it and
everyone should see the answer. That way *everyone*
improves their chances of not making the same mistake.

Alan G.

>
>
>
> Jason Child wrote:
>
> > Alan Gauld wrote:
> >
> >>>oops, I forgot to add the s = 1 and s=0 lines to the example code
i
> >>>posted...
> >>>
> >>>
> >>
> >>OK, To save us guessing, why don't you post it with the s=1/0 and
> >>also the actual output pattern you get?
> >>
> >>Seeing the error is a very powerful technique for guessing what
may
> >>be at fault. A second hand description is never as precise.
> >>
> >>Alan G
> >>
> >>
> >>
> > I've got a silly question.
> > #######################
> > P1 = "prefix1"
> > P2 = "prefix2"
> >
> > def my_func(list, items):
> >    s = 0
> >    out = ""
> >    for i in range(len(list)):
> >        if s == 0:
> >            p = P1
> >            s = 1
> >        else:
> >            p = P2
> >            s = 0
> >        for j in range(len(items)):
> >            out += p +items[j]
> >    return out
> > ########################
> >
> > If my input was:
> > list = ["car list 1","car list 2"]
> > items = ["torino","mustang","elantra"]
> >
> > for output I get:
> >
prefix1torinoprefix1mustangprefix1elantraprefix1torinoprefix1mustangpr
efix1elantra
> >
> > when I expect:
> >
prefix1torinoprefix1mustangprefix1elantra*prefix2*torino*prefix2*musta
ng*prefix2*elantra
> >
> >
> >-- 
> >Jason Christopher Child
> >
> >Computer Network Service Professionals
> >VOZ Online
> >
> >
>
>---------------------------------------------------------------------
---
> >
> >_______________________________________________
> >Tutor maillist  -  Tutor at python.org
> >http://mail.python.org/mailman/listinfo/tutor
> >
> >
>
>
> -- 
> Jason Christopher Child
>
> Computer Network Service Professionals
> VOZ Online
>
>
>



More information about the Tutor mailing list