-
-
Save joshourisman/1918906 to your computer and use it in GitHub Desktop.
Rounding with string homework
This file contains hidden or 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 | |
def string_round(x): | |
number = str(x) | |
tenths = number[number.find('.') + 1][0] | |
solved = (x + 5 + | |
tenths.find('5') + | |
tenths.find('6') + | |
tenths.find('7') + | |
tenths.find('8') + | |
tenths.find('9')) | |
print str(solved)[:str(solved).find('.')] | |
string_round(x) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment