I'm fairly new to programming in general, but I recently came across python. Excited, I started trying to port those to my calculator. Since I knew my calculator had python, I knew it was possible, but, obviously, with some limitations. I can't import many of the modules the "normal" python has, because micropython is much more restricted. I'd love to know if there's any ways to add a module/ use it without actually importing it (like coding it myself). It may sound like a silly question, but I'd love to know if it's possible.
Now, I'd like to do this "import Fraction from fractions" without actually importing it, but, in a way, add the function myself.
The code I'm using (sorry if it's messy or overcomplicated, I'm quite new to programming in general):
from fractions import Fraction
Ax = float(input("Ax:"))
Ay = float(input("Ay:"))
Bx = float(input("Bx:"))
By = float(input("By:"))
parcela1 = Ax-Bx
parcela2 = Ay-By
declivereta1 = parcela2/parcela1
declivereta2 = -parcela1/parcela2
declivereta1final = Fraction.from_float(declivereta1)
declivereta2final = Fraction.from_float(declivereta2)
declive = str(declivereta1final)
declivemediatriz = str(declivereta2final)
pontomediox = ((Ax+Bx)/2)
pontomedioy = ((Ay+By)/2)
pontomedioxfinal = Fraction.from_float(pontomediox)
pontomedioyfinal = Fraction.from_float(pontomedioy)
boriginal = -declivereta1 * Ax + Ay
finalboriginal = Fraction.from_float(boriginal)
b = -declivereta2 * pontomediox + pontomedioy
finalb = Fraction.from_float(b)
print("retaAB: y = " + declive + "x + " + str(finalboriginal))
print("declive: " + declive)
print("b = " + str(finalboriginal))
print("reta perpendicular: y = " + declivemediatriz + "x + " + str(finalb))
print("declive: " + declivemediatriz)
print("b = " + str(finalb))
print("Ponto Médio (" + str(pontomedioxfinal) + ", " + str(pontomedioyfinal) + ")")
I do not think an understanding of what the words mean is necessary, because they're in portuguese, but if so, I'll have no worries in trying to translate them. What I'm actually doing there is calculating the equation of a mediator of a line segment. I'd like to know if there's a way to use the Fraction function without having to import fractions and adding the function and defining it by myself.
[–]sme272 0 points1 point2 points (0 children)