Python :: Aufgabe #24 :: Lösung #1

5 Lösungen Lösungen öffentlich
#24

Abstand zweier Punkte

Anfänger - Python von Dome - 03.01.2013 um 01:09 Uhr
Schreiben Sie ein Programm, welches den Abstand zweier Punkte berechnet. Zuvor müssen die Koordinaten beider Punkte abgefragt werden.

Konsolenausgabe:

x1:1
y1:1
x2:2
y2:2
1.4142135623730951
#1
vote_ok
von _Mala_Fide_ (820 Punkte) - 10.12.2014 um 13:10 Uhr
Quellcode ausblenden Python-Code
#!/usr/bin/python

import math
def Abstand(x1, y1, x2, y2):
   Abstand_x = x2 - x1
   Abstand_y = y2 - y1
   Abstand_zum_Quadrat = Abstand_x**2 + Abstand_y**2
   Ergebnis = math.sqrt(Abstand_zum_Quadrat)
   return Ergebnis
print Abstand(input("x1:"), input("y1:"), input("x2:"), input("y2:"))


Nocheinmal in stark verkürztem Code.

Quellcode ausblenden Python-Code
#!/usr/bin/python

import math
def Abstand(x1, y1, x2, y2):
	return math.sqrt(((x2-x1)**2)+((y2-y1)**2))
print Abstand(input("x1:"), input("y1:"), input("x2:"), input("y2:"))

Kommentare:

Für diese Lösung gibt es noch keinen Kommentar

Bitte melden Sie sich an um eine Kommentar zu schreiben.
Kommentar schreiben