[Tutor] Is it pythonesque
bermanrl at cfl.rr.com
Sun Jan 24 17:13:37 CET 2010
Given the following code snippets:
s1 = raw_input('Enter fraction as N,D or 0,0 to exit>>')
delim = s1.find(',')
if delim < 0:
print 'invalid user input'
n = int(s1[0:delim])
d = int(s1[delim+1::])
n,d = getuserinput()
if n == 0 or d == 0: return 0
n and d are always returned provided the input is given as n,d. n/d will
print an error message and the loop will reiterate until the user format is
correct. Please note there is no true ending return for getuserinput() as it
is hung off an if statement and if by some chance it breaks, it should
return None which will abort the program. While I suspect this style is
devious, is it dangerous or 'wrong' to use. Comments and other renditions
are most welcome.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Tutor