[Tutor] Control flow

Gilbert Tsang gtsang at lnxw.com
Mon Jan 31 21:29:25 CET 2005


Thanks for the enthusiasm on how input/raw_input() works - my original 
intention was to ask a question on control flow so I didn't spend that 
much time testing out this piece of input code besides typing. But I did 
learn a lot. Thanks!

Gilbert

Jacob S. wrote:

> I noticed that too, Liam.
> b = input("Weather is really bad, still go out to jog? [y/n]    ") # 
> Would it kill you to have whitespace in a prompt?
> should really be
> b = raw_input("Weather is really bad, still go out to jog? [y/n]    ")
> to get the effect he wants.
>
> input() doesn't only take integers, it takes valid python objects. 
> Integers are objects, but so are lists, dictionaries, tuples,
> actually it takes everything, BUT!!! it trys to return a valid python 
> object for input.
> So it will take a string--don't quote me on this--if you explicitly 
> put the string in quotes.
> If you don't put the string in quotes, it instead searches the 
> namespaces for that object.
> So say the user typed in bad_weather when the interpreter gave that 
> prompt. Then, b == "y" evaluates true because bad_weather == "y". Did 
> I explain it right? Or am I trying to explain something you already 
> know? I know I get frustrated when people try to explain concepts that 
> I already know...
>
> HTH,
> Jacob Schmidt
>
>> < erk, to the list, to the List!>
>>
>> if ( bad_weather =='y' ):
>>   # ask user only if weather is bad.
>>   b = input ( "Weather is really bad, still go out to jog?[y/n]" )
>>   if b == 'y':
>>      go_jogging()
>>
>> Anyone else notice that he's never gonna go jogging if the weather is 
>> bad?
>> Unless I've got input() wrong, it only takes integers... ?
>>
>> Regards,
>>
>> Liam Clarke
>>
>> -- 
>> 'There is only one basic human right, and that is to do as you damn 
>> well please.
>> And with it comes the only basic human duty, to take the consequences.
>>
>>
>> -- 
>> 'There is only one basic human right, and that is to do as you damn 
>> well please.
>> And with it comes the only basic human duty, to take the consequences.
>> _______________________________________________
>> Tutor maillist  -  Tutor at python.org
>> http://mail.python.org/mailman/listinfo/tutor
>>
>>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor




More information about the Tutor mailing list