# Given a variable, x, that stores the # value of any decimal number, write Python # code that prints out the nearest whole # number to x. # If x is exactly half way between two # whole numbers, round up, so # 3.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 solved # using 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 #ENTER CODE BELOW HERE
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question