Re: [Tutor] help with homework

2012-10-29 Thread Asokan Pichai
On Mon, Oct 29, 2012 at 2:28 PM, Alan Gauld wrote: > On 29/10/12 08:37, Asokan Pichai wrote: > >>> teachers put stupid artificial constraints on your code, >> >> >>> >>> such as banning the use of len(). >> >> >> There may be legitim

Re: [Tutor] help with homework

2012-10-29 Thread Alan Gauld
On 29/10/12 08:37, Asokan Pichai wrote: teachers put stupid artificial constraints on your code, such as banning the use of len(). There may be legitimate learning outcomes for a teacher to specify such conditions. In that ca

Re: [Tutor] help with homework

2012-10-29 Thread Asokan Pichai
[SNIPPED] > > Always use a while loop in this situation, This is excellent advice. Use a for loop in two situations: 1. Iterating a fixed(known) number of times 2. Iterating through the contents of any container Use a while loop to iterate as long as a condition applies. > regardless of wheth

Re: [Tutor] help with homework

2012-10-28 Thread Mark Lawrence
On 29/10/2012 01:40, Matthew Ngaha wrote: In your original getNames do something like this. Initialise a counter to zero. Every time you get a valid name increment the count. If the count is three you're finished. hey i was looking at the question as im learning also. With the counter, would

Re: [Tutor] help with homework

2012-10-28 Thread Matthew Ngaha
> > In your original getNames do something like this. >> Initialise a counter to zero. >> Every time you get a valid name increment the count. >> If the count is three you're finished. >> > hey i was looking at the question as im learning also. With the counter, would you use a while loop instead o

Re: [Tutor] help with homework

2012-10-28 Thread Alan Gauld
On 28/10/12 21:37, Sandra Beleza wrote: def GetNames(): names=[] while len(names)<3: name=raw_input("Name: ") if name in names: print name, "is already in the data. Try again." if name not in names: names.append(name) names.sort

Re: [Tutor] help with homework

2012-10-28 Thread Mark Lawrence
On 28/10/2012 21:37, Sandra Beleza wrote: Hi, I have to write a script that asks the user for names one at a time, and accept the name only if the user did not gave it before. The script has to do this until it gets 3 unique names. So far I have this: def GetNames(): names=[] while le

[Tutor] help with homework

2012-10-28 Thread Sandra Beleza
Hi, I have to write a script that asks the user for names one at a time, and accept the name only if the user did not gave it before. The script has to do this until it gets 3 unique names. So far I have this: def GetNames(): names=[] while len(names)<3: name=raw_input("Name: ")