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。另外请不要过于批评实际的代码。我还在学习。它的蟒蛇顺便说一下。谢谢!
答案 0 :(得分: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
答案 1 :(得分: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答案 2 :(得分:0)
你可以把真的放在一边;在开始时,然后从客户那里获取输入,如果客户说不,则将其切换为false。
答案 3 :(得分: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))