Re: [Tutor] Is it pythonesque

2010-01-25 Thread spir
On Sun, 24 Jan 2010 11:13:37 -0500 "Robert Berman" wrote: > Good morning, > > > > Given the following code snippets: > > > > def getuserinput(): > > while True: > > s1 = raw_input('Enter fraction as N,D or 0,0 to exit>>') > > delim = s1.find(',') > > if del

Re: [Tutor] Is it pythonesque

2010-01-24 Thread Robert Berman
Thank you for the snippet and the insight. Robert -Original Message- From: tutor-bounces+bermanrl=cfl.rr@python.org [mailto:tutor-bounces+bermanrl=cfl.rr@python.org] On Behalf Of Alan Gauld Sent: Sunday, January 24, 2010 12:17 PM To: tutor@python.org Subject: Re: [Tutor] Is it

Re: [Tutor] Is it pythonesque

2010-01-24 Thread Alan Gauld
"Robert Berman" wrote def getuserinput(): while True: s1 = raw_input('Enter fraction as N,D or 0,0 to exit>>') delim = s1.find(',') if delim < 0: print 'invalid user input' else: n = int(s1[0:delim]) d = int(s1[delim+1::])

Re: [Tutor] Is it pythonesque

2010-01-24 Thread शंतनू
If the input has more than one ',', e.g. '1,2,3'. You may like to use 'split' function, and avoid find. On 24-Jan-2010, at 9:43 PM, Robert Berman wrote: > Good morning, > > Given the following code snippets: > > def getuserinput(): > while True: > s1 = raw_input('Enter fraction a

[Tutor] Is it pythonesque

2010-01-24 Thread Robert Berman
Good morning, Given the following code snippets: def getuserinput(): while True: s1 = raw_input('Enter fraction as N,D or 0,0 to exit>>') delim = s1.find(',') if delim < 0: print 'invalid user input' else: n = int(s1[0:delim