저는 파이썬에서 새로운 프로그래밍입니다. 나는 단순히 최저 지불 (10 시부 터 시작하는)을 취하고 나머지 12 개월 만에 지불하는 기능을 만들려고하고있다.내 루프가 내 함수를 호출하지 않습니다.
함수 밖에서 함수를 호출하고 나머지 잔액이 0인지 또는 0보다 작은 지 확인하는 루프를 사용하고 있습니다. 그렇지 않은 경우 가장 낮은 금액 인 + 10 달러를 인상하고 해당 함수를 다시 호출하십시오. 잔액이 0 또는 0보다 작 으면 가장 낮은 금액을 출력하십시오.
다음과 같이 이론적으로 출력 같아야
테스트 케이스 1 :
balance = 3329
annualInterestRate = 0.2
Result Your Code Should Generate:
******Lowest Payment: 310******
Test Case 2:
balance = 4773
annualInterestRate = 0.2
Result Your Code Should Generate:
** 최저 지불 : 440 * *
Test Case 3:
balance = 3926
annualInterestRate = 0.2
Result Your Code Should Generate:
을 ** 최저 지불 :
balance = 100
annualInterestRate = 0.2
per_month = (annualInterestRate/12)
# Answer is 0.0166666 but I need it to be 0.01, so figured out to convert to string then to float, not the most elegant , but practical. :)
convert_to_str = str(per_month)[:4]
per_month = float(convert_to_str)
lowest_payment = 0
def main():
i = 0
while i < 11:
global balance
global lowest_payment
global per_month
balance = balance - lowest_payment
balance = ((balance * per_month) + balance)
i = i +1
#print (balance)
main()
if balance <= 0 or balance == 0:
print "Lowest Payment: " + str(lowest_payment)
else:
lowest_payment = lowest_payment + 10
main()
문제는 그게 내 기능을 실행하지 않습니다이다, 다시 루프를 통해 이동 : *
360 * 지금까지이 내가 가진 것입니다. 나는 if와 while 루프를 시도했다. 아래 while 루프, 무한 루프 제공 :
while balance >= 0 or balance != 0:
lowest_payment = lowest_payment + 10
main()
if balance <= 0:
print "Lowest Payment: " + str(lowest_payment)
도움을 주시면 대단히 감사하겠습니다.
예상되는 출력은 무엇입니까? 이론적으로 – Christian
, 균형 = 3329 annualInterestRate = 0.2 는 코드 생성해야합니다 최저 지불 : (310) 테스트 케이스 2 : 균형 = 4773 annualInterestRate = 0.2 는 생성해야합니다 : 최저 지불 : 440 테스트 사례 3 : balance = 3926 annualInterestRate = 0.2 최저 최저 요금 : 360 –
사용중인 공식이 정확합니까? – Christian