0
def min_payment():
    ''' Calculates the minimum payment due on credit card
        depending on the credit card balance'''
    print("Tiny National Bank of Walterville")
    print("Credit Card Payments")


    balance = float(input("Please enter Credit Card Balance"))
    print("Credit Card Balance: " ,round(float(balance), 2))
    min1 = 12.00
    min2 = round(.027 * balance, 2)

    if min2 > min1:
        print("Minimum payment due: ", min2)

    elif balance <= 0:
        print("No payment due")

    elif balance < min1:
        print("Minimum payment due: ", balance)

    else:
        print("Minimum payment due: ", min1)    

如果有人能告诉我如何循环,以便我可以根据用户输入重复它,那将非常有帮助。我基本上希望它说类似“另一个客户(y 或 n)?”

要求用户选择 y 或 n。另外请不要对实际代码过于挑剔。我还在学习。顺便说一句,它的蟒蛇。谢谢!

4

4 回答 4

1
isDue=True

while isDue==True:

 balance = float(input("Please enter Credit Card Balance"))
 print("Credit Card Balance: " ,round(float(balance), 2))
 min1 = 12.00
 min2 = round(.027 * balance, 2)

 if min2 > min1:
    print("Minimum payment due: ", min2)

 elif balance <= 0:
     print("No payment due")

 elif balance < min1:
     print("Minimum payment due: ", balance)

 else:
     print("Minimum payment due: ", min1)

//在while循环的某处设置isDue = False

于 2013-11-04T07:33:53.790 回答
1
print("Tiny National Bank of Walterville")
print("Credit Card Payments")

while True:
    balance = float(input("Please enter Credit Card Balance"))
    print("Credit Card Balance: " ,round(float(balance), 2))
    min1 = 12.00
    min2 = round(.027 * balance, 2)

    if min2 > min1:
        print("Minimum payment due: ", min2)

    elif balance <= 0:
        print("No payment due")

    elif balance < min1:
        print("Minimum payment due: ", balance)

    else:
        print("Minimum payment due: ", min1)

    answer = ''
    while answer not in ('y', 'n'):
        answer = input("Another customer (y or n)").lower()
    if answer == 'n':
        break
于 2013-11-04T07:30:23.890 回答
0

你可以把 while True; 一开始,然后从客户那里获取输入,如果客户说不,则将其切换为 false。

于 2013-11-04T07:29:29.397 回答
0
Outstanding = 59400
interestrate = 4.2

#print("Month", "\t", "Interest+GST", "\t\t", "MinAmtDue", "\t\t\t", "Balance")
#print("-----", "\t\t", "-------", "\t\t", "--------", "\t\t\t", "-------")

month = 0
totpmt = 0
interest_GST = 0
minamtdue = 0
outstandingamt1 = Outstanding
while (outstandingamt1 + interest_GST - minamtdue) > 0 :
    month += 1
    interest_GST = outstandingamt1*4.2/100`enter code here`
    minamtdue = outstandingamt1 * 5/100
    #minamtdue = 12000enter code here
    outstandingamt1 = outstandingamt1 + interest_GST - minamtdue`enter code here`
    print(month, "\t\t\t", round(interest_GST,2), "\t\t", round(minamtdue,2), "\t\t\t", round(outstandingamt1,2))
    totpmt = totpmt + minamtdue
print(month+1, "\t\t\t", 0, "\t\t", round(outstandingamt1,2), "\t\t\t", 0)
print("Total Amount to be paid in ", month+1, "months= ", round(totpmt+outstandingamt1 , 2))
于 2019-10-09T11:55:53.433 回答