Hallo,
meine while schleife sieht so aus:
while end_of_month <= portion_down_payment:
allerdings ist die lösung 181, obwohl ich 183 brauche und im 183. Monat ist end_of_month bei 255000, während portion_down_payment: bei 250000 ist. Ich brauche quasi den integer, indem "end_of_month" über "portion_down_payment" ist. Jemand eine Ahnung wie das funktionieren soll?
while schleife das erste mal über die Bedingung
- __blackjack__
- User
- Beiträge: 14052
- Registriert: Samstag 2. Juni 2018, 10:21
- Wohnort: 127.0.0.1
- Kontaktdaten:
@akbabami: Das wird schwierig zu beantworten weil aus dem gezeigten weder klar wird was sich in der Schleife verändert, noch wie es sich verändert, noch was/wo/wie die 181 zustande kommt.
“Vir, intelligence has nothing to do with politics!” — Londo Mollari
def berechnen(end_of_month):
end_of_month = end_of_month - 0.01 * monthly_salary
end_of_month = end_of_month + current_savings + (((end_of_month + current_savings)*(0.04/12)))
end_of_month = end_of_month + 0.01 * monthly_salary
return end_of_month
def firstmonth():
end_of_month = current_savings + r #1000 + 4% Rendite
end_of_month= end_of_month + 0.01 * monthly_salary #1103.333
x = 0
while end_of_month < portion_down_payment :
x += 1
berechnen(end_of_month)
end_of_month = berechnen(end_of_month)
print(x)
firstmonth()
also in der Schleife wird etwas berechnet und überprüft & so gesehen stimmt die Rechnung, nur es bleibt halt nur bei 181 statt wie eigentlich 183
end_of_month = end_of_month - 0.01 * monthly_salary
end_of_month = end_of_month + current_savings + (((end_of_month + current_savings)*(0.04/12)))
end_of_month = end_of_month + 0.01 * monthly_salary
return end_of_month
def firstmonth():
end_of_month = current_savings + r #1000 + 4% Rendite
end_of_month= end_of_month + 0.01 * monthly_salary #1103.333
x = 0
while end_of_month < portion_down_payment :
x += 1
berechnen(end_of_month)
end_of_month = berechnen(end_of_month)
print(x)
firstmonth()
also in der Schleife wird etwas berechnet und überprüft & so gesehen stimmt die Rechnung, nur es bleibt halt nur bei 181 statt wie eigentlich 183
Warum hast Du jetzt einen neuen Beitrag aufgemacht? Hier fehlen immer noch eine ganze Reihe von Variablen. Warum rufst Du zwei mal `berechnen` auf?
Zu den Anmerkungen im anderen Beitrag, `x` ist ein schlechter Variablenname für die Anzahl an Monaten. Bei `firstmonth` erwarte ich auch keine Berechnung einer Anzahl an Monaten.
Zu den Anmerkungen im anderen Beitrag, `x` ist ein schlechter Variablenname für die Anzahl an Monaten. Bei `firstmonth` erwarte ich auch keine Berechnung einer Anzahl an Monaten.
- __blackjack__
- User
- Beiträge: 14052
- Registriert: Samstag 2. Juni 2018, 10:21
- Wohnort: 127.0.0.1
- Kontaktdaten:
Der Code mal um die fehlenden Argumente bei den Funktionen ergänzt:
`r` und `berechnen` sind auch keine guten Namen und sollten besser benannt werden. `end_of_month` scheint mir auch falsch/schlecht benannt zu sein und für die magischen literalen Zahlen gäbe es vielleicht auch sinnvolle Konstantennamen.
Code: Alles auswählen
def berechnen(end_of_month, monthly_salary, current_savings):
end_of_month -= 0.01 * monthly_salary
end_of_month += current_savings + (
(end_of_month + current_savings) * (0.04 / 12)
)
return end_of_month + 0.01 * monthly_salary
def firstmonth(monthly_salary, current_savings, r, portion_down_payment):
end_of_month = current_savings + r + 0.01 * monthly_salary
x = 0
while end_of_month < portion_down_payment:
end_of_month = berechnen(end_of_month, monthly_salary, current_savings)
x += 1
print(x)
“Vir, intelligence has nothing to do with politics!” — Londo Mollari