Created
February 26, 2012 20:56
-
-
Save gsiegman/1918954 to your computer and use it in GitHub Desktop.
Glenn solution to https://gist.github.com/1918836
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Given a variable, x, that stores | |
#the value of any decimal number, | |
#write Python code that prints out | |
#the nearest whole number to x. | |
#You can assume x is not negative. | |
# x = 3.14159 -> 3 (not 3.0) | |
# x = 27.63 -> 28 (not 28.0) | |
x = 3.14159 | |
#DO NOT USE IMPORT | |
#ENTER CODE BELOW HERE | |
#ANY CODE ABOVE WILL CAUSE | |
#HOMEWORK TO BE GRADED | |
#INCORRECT | |
str_x = str(x) | |
dec_location = str_x.find(".") | |
num_after_dec_location = str_x[dec_location + 1] | |
y = x | |
y = y + (str(num_after_dec_location).find("5")) + 1 | |
y = y + (str(num_after_dec_location).find("6")) + 1 | |
y = y + (str(num_after_dec_location).find("7")) + 1 | |
y = y + (str(num_after_dec_location).find("8")) + 1 | |
y = y + (str(num_after_dec_location).find("9")) + 1 | |
print str(y)[0:dec_location] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment