Hallo,
heute bin ich mit einem Bug im Rucksack unterwegs.
Ich versuche folgende Zahl 11.313708498984761 in Python zu quadrieren. Das Ergebnis müsste 128 sein, doch er gibt 128,00000000000003 aus und ich verstehe nicht wie ich das präzisieren könnte.
Es wäre schön, falls mir jemand weiterhelfen könnte.
Mit freundlichen Grüßen
JUCEL
PS: Hier mein derzeitiger Code:
# This Script was made to calculate the distance to celestial bodies in space (nearby milkyway).
import math
import decimal
import datetime
import random, string
sin = math.sin;
degrees = math.radians;
decimal.getcontext().prec = 200;
decimal = decimal.Decimal;
# Log-File, Datum, Star-Name
request = input("Hello, please choose between following options:\nDistance-Calculator [1] \nProtokoll [2]\nExit [q]\nOption: ")
if request == str("1"):
print("Please insert following required data:")
angle1 = input("Angle 1 (°): ")
angle2 = input("Angle 2 (°): ")
distance_In = decimal(input("Distance between the angles (Kilometre): "))
# Angles
summary = decimal(angle1) + decimal(angle2)
angle3 = 180 - float(summary)
# Distances
distance_In_parsec = distance_In * decimal(0.000000000000060019)
# Distance_a
distance_out_a_parsec = decimal(distance_In) * decimal((sin(degrees(decimal(angle1)))/sin(degrees(decimal(angle3))))) * decimal(0.000000000000060019)
distance_out_a_ligh_years = decimal(distance_out_a_parsec) * decimal(3.26156)
distance_out_a_astronomic_unit = decimal(distance_out_a_parsec) * decimal(206265)
print("Distance a: \n ", distance_out_a_parsec, "parsec \n ", distance_out_a_ligh_years, "ly \n", distance_out_a_astronomic_unit, "AU \n")
# Distance_b
distance_out_b_parsec = decimal(distance_In) * decimal((sin(degrees(decimal(angle2)))/sin(degrees(decimal(angle3))))) * decimal(0.000000000000060019)
distance_out_b_ligh_years = decimal(distance_out_b_parsec) * decimal(3.26156)
distance_out_b_astronomic_unit = decimal(distance_out_b_parsec) * decimal(206265)
print("Distance b: \n ", distance_out_b_parsec, "parsec \n ", distance_out_b_ligh_years, "ly \n", distance_out_b_astronomic_unit, "AU \n")
# Distance_center
half = decimal(distance_In)/2
distance_out_center_dump = distance_out_a_parsec * distance_out_a_parsec - half * half
distance_out_center_parsec = decimal(math.sqrt(abs(decimal(distance_out_center_dump)))) * decimal(0.000000000000060019)
distance_out_center_light_years = decimal(distance_out_center_parsec) * decimal(3.26156)
distance_out_center_astronomic_unit = decimal(distance_out_center_parsec) * decimal(206265)
print("Distance from the center of ellipsis: \n ", distance_out_center_parsec, "parsec \n ", distance_out_center_light_years, "ly \n", distance_out_center_astronomic_unit, "AU")
# Protocol
elif request == str("2"):
pass
elif request == str("q"):
exit(0)