I'm stuck on a beginner level coding problem. Goal is to round a float number and output an integer. So x = 3.14159
, output 3
(not 3.0
). We're supposed to be able to do this using only what we've learned, and what we've learned is only 3 functions: .find
, <string>[:]
, and converting the given x = float num
into a string, via str()
.
How should I be thinking about this? When I write out what logically needs to happen, I always find myself needing if()
.
I ended up getting partial credit with the following code:
given: x = 3.14159
x = int(round(x))
print x
But I would like to solve it without int()
or round()
, or if()
. My first thought was to use x[2:3]
and x[3:4]
to check the tenths and hundredths place values, but to proceed I still run into the if()
wall.