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
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
[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
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
>
> 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
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
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
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: ")