def endswithint(s): return not s.rstrip('0123456789').endswith('.') def addpoint(s): """ returns '.' if s ends with integer, nothing if it endswith float """ if endswithint(s): return '.' return "" a="2+1" b="3" print eval(a+'/'+b) # integer division print eval('1.0*'+a+'/'+b) ##also does not make it a+=addpoint(a) print eval(a+'/'+b)
Edited by snippsat: n/a
Are you able to help answer this sponsored question?
Questions asked by members who have earned a lot of community kudos are featured in order to give back and encourage quality replies.