Wednesday, September 4, 2013

Python: More elegant Way of Writing this if statement

Python: More elegant Way of Writing this if statement

Please suggest a more elegant alternative to writing this if/elif in python
if i >= 10 and i<20:
c = 2
r = i-10
elif i>=20 and i<30:
c = 4
r = i-20
elif i>=30 and i<40:
c = 6
r = i-30
elif i>=50 and i<60:
c = 8
r = i-50
elif i>=60 and i<70:
c = 10
r = i-60
elif i>=70 and i<80:
c = 12
r = i-70

No comments:

Post a Comment