python循环计数器_向while循环python添加计数器

只需创建一个变量来存储不正确的猜测,并使用if条件来决定何时发生5个不正确,就可以停止循环。如下所示:Ac=L*xm

count = 0 #variable to store incorrect guesses

#ask user to work out A (monthly interest * capital)

while True:

if count == 5: #IF COUNT(incorrect) is 5 times

break #stop loop

else: # if not continue normally

A = raw_input("What do you think the monthly interest x the amount you are borrowing is? (please use 2 d.p.) £")

A = float(A)

# tell user if they are correct or not

if A == round(Ac, 2):

print("correct")

break

elif A == round(L * x, 2):

print(

"incorrect. You have used the APR rate, whic is an annual rate, you should have used this rate divided by 12 to make it monthly")

count += 1

elif A == round(L / (x * 100), 2):

print(

"incorrect. You have used the interest rate as a whole number when you should have used it as a decimal, and divided it by 12 for the monthly rate")

count += 1

else:

print(

"Wrong, it seems you have made an error somewhere, you should have done the loan amount multiplied by the monthly rate")

count += 1

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值