Also because of my work in number theory, I often need to have the root floor and root ceing of a number.
This is my function for computing those two numbers from a target number.
Science and Math Researcher (For Fun)
# Imports #
import sys, os, importlib, inspect, locale, time, math
from datetime import datetime
locale.setlocale(locale.LC_ALL, '') # Set the locale for your system 'en_US.UTF-8'
# Main #
def main():
# Main Code
print("Root floor: {}, Ceiling: {}".format(*f_RootSplit(91)))
print("Root floor: {}, Ceiling: {}".format(*f_RootSplit(161)))
#-----------Basement------------
# Functions #
# Normal Functions
def f_RootSplit(v_Num):
"""&Syntax: INT; Returns: LIST of INT;
Desc.: Converts v_Num into root floor and root ceiling.
Test: print("Root floor: {}, Ceiling: {}".format(*f_RootSplit(91)))"""
v_RootFloor = math.sqrt(v_Num) // 1 ## Compute sqrt floor
v_RootCeiling = v_RootFloor + 1 ## Create sqrt ceiling
return v_RootFloor, v_RootCeiling
# Main Loop #
if __name__ == '__main__':
main()
Why not use math.floor()
and math.ceil()
?
Try ...
sf = "For {} Root floor: {}, Ceiling: {}"
n = 91
print(sf.format(n, math.floor(n**0.5), math.ceil(n**0.5)))
n = 161
print(sf.format(n, math.floor(n**0.5), math.ceil(n**0.5)))
We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.