Exakten Wert beim Quadrieren von Floats (Python)?

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)
Computer, programmieren, Informatik, Python, Python 3
wie kann ich einen 5v 3-pin 5vdg in 12v 4 pin header auf Mainboard anschließen?

Hallo,

ich habe seit kurzem einen neuen CPU Kühler als auch neue Lüfter alle inkl. ARGB, jedoch haben alle davon einen 3-pin 5vdg Stecker, mein Mainboard jedoch hat lediglich einen 4 pin RGB Header.
Besteht eine Möglichkeit wie ich dennoch alles an mein Mainboard angeschlossen bekomme mit hilfe von irgendwelchen adaptern oder ähnlichem?

Ich habe breits gelesen das man das normalerweise ohne Probleme kann und man lediglich ein Nädelchen vom 4 Pin Header außen vor lässt das geht jedoch bei meinen 3-Pin steckern nicht, da sie nach 2 Nadeln eine Lücke haben und dann kommt die 3.

Über hilfe würde ich mich sehr freuen.

Mein Mainboard: https://motherboarddb.com/motherboards/514/Z370P%20D3/

Mein CPU-Kühler: https://www.caseking.de/jonsbo-cr-1100-cpu-kuehler-argb-2x-120mm-grau-cpjb-005.html

Meine Lüfter: https://www.alternate.de/AZZA/4-X-HURRICANE-II-DIGITAL-RGB-FAN-120mm-plus-Digital-RF-Remote-Geh%C3%A4usel%C3%BCfter/html/product/1639314

Die Stecker die meine Lüfter/Kühler haben: https://www.google.com/search?q=3-pin+5vdg&tbm=isch&ved=2ahUKEwirx9WyperuAhWF6qQKHVMxCewQ2-cCegQIABAA&oq=5VDG+&gs_lcp=CgNpbWcQARgBMgQIABATMggIABAFEB4QE1CvygFYh9IBYOjeAWgCcAB4AIABYYgBYZIBATGYAQCgAQGqAQtnd3Mtd2l6LWltZ8ABAQ&sclient=img&ei=aZIpYOvuKoXVkwXT4qTgDg&bih=937&biw=1920&rlz=1C1CHBF_deDE777DE777#imgrc=t2tPLC2PXtOKGM

LG Niko

Computer, Technik, Technologie, Spiele und Gaming

Meistgelesene Beiträge zum Thema Computer