the round function should be improved, the round function is supposed to round up numbers that are in a decimal format. I have found that the round function only looks at the first decimal point, for example when I enter this:
print(round(1.45), round(1.54))
as a result I get:
1 2
I have created some new code that works as the round function is supposed to:
def rounding(num):
#this code was made by anon
#this looks to see if the num is a decimal
if num % 1 != 0:
#sees if the first decimal digit is greater than or equal to 0.5
if num % 1 >= 0.5:
#retuns the number rounded up
return int(num + 1)
#sees if the first decimal digit is less than 0.5
elif num % 1 < 0.4:
#returns the number rounded down
return int(num)
#this is were things get tricky, this is for when the decimal is 0.4, or anything with 0.4 as the first decimal digit
else:
#create our list, which just stretches out the number
stretch = []
#this is the number we are going to be adding to the list
stretch += str(num)
#this is a latch to tell us if we have found the decimal point
deci_found = False
#this is were we look through the number
for digit in stretch:
#we want to know when we have found the decimal point
if deci_found:
#this asks if the digit is greater than or equal to 5
if int(digit) >= 5:
#if it is, we add 1 to the number and return it
return int(num + 1)
#if it is not, we ask if it is less than 4
elif int(digit) < 4:
#if it is, we return the number
return int(num)
#we do not look for any 4s because those are the numbers that will be rounded up
#this finds the decimal point, and activates the latch if true
if digit == ".":
deci_found = True
#if the number is not a decimal, we just return the number
else:
return num