Also ich versuche, eine Art Taschenrechner zu erstellen, der alle Arten von Gleichungen behandelt. Alles, was Sie tun müssen, ist einzugeben, worauf Sie Hilfe brauchen, und es wird Ihnen eine Reihe von Fragen stellen, basierend darauf, welche Gleichung Sie benötigen, und es wird einen Wert zurückgeben. Ich versuche es so zu machen, dass wenn eine bestimmte Zeichenfolge eingegeben wird, eine bestimmte Reihe von Fragen gestellt wird. Es fragt jedoch alle Fragen unabhängig davon, was ich eingegeben habe. Ich benutze Python 3.6.Python - Wenn Anweisung, wenn Eingabe ist eine bestimmte Zeichenfolge
whichEquation = input("What are you having trouble with? ")
if whichEquation:
"interest"
r = float(input("What is the interest rate?: "))
C = float(input("Deposit cash: "))
t = float(input("For how many years will your deposit be invested?: "))
n = float(input("How many times per year is the interest compounded?: "))
interest = C * (1 + r/n)**(n*t)
print("Your future value is: ",interest,"dollars")
if whichEquation:
"slope"
y1 = float(input("First y point: "))
y2 = float(input("Second y point: "))
x1 = float(input("First X point: "))
x2 = float(input("Second X point: "))
slope = (y2 - y1)/(x2 - x1)
print("The slope is:",slope)
So wie würde ich zeige nur entweder die ‚Neigung‘ Gleichung oder die ‚Interesse‘ Gleichung, wenn whichEquation Neigung oder Interesse ist.
'if whichEquation:" interest "' -> Was denkst du, was dieser Code bedeutet? Dasselbe gilt für 'if whichEquation:" slope "'. – ForceBru
Mein Verständnis war es bedeutet, dass wenn whichEquation die Zeichenfolge "Interesse" ist, dann wird es eine bestimmte Sache tun. Dasselbe gilt für die Steigung. –
Das 'if whereEquation:' bedeutet 'wenn whichEquation ist _truthy_, d. H. Keine leere Zeichenfolge, nicht Null usw., dann führe den Block aus', also in deinem Fall besteht der Block aus einer bloßen Zeichenkette und läuft nichts. – ForceBru