#Given a variable, x, that stores thevalue of any decimal number, write Pythoncode that prints out the nearest wholenumber to x.If x is exactly half way between twowhole numbers, round up, so3.5 rounds to 4 and 2.5 rounds to 3.You may assume x is not negative.Hint: The str function can convert any number into a string.eg str(89) converts the number 89 to the string '89'Along with the str function, this problem can be solvedusing just the information introduced in unit 1.x = 3.14159>>> 3 (not 3.0)x = 27.63>>> 28 (not 28.0)x = 3.5>>> 4 (not 4.0)
x = 3.14159
x = x+0.5
#ENTER CODE BELOW HERE
num = str(x).find('.')
print x[:num]#这里我知道得出来肯定为空了,所以求问应该怎么处理?谢谢
x = 3.14159
x = x+0.5
#ENTER CODE BELOW HERE
num = str(x).find('.')
print x[:num]#这里我知道得出来肯定为空了,所以求问应该怎么处理?谢谢