循环直到特定输入

时间:2014-10-12 17:02:36

标签: python loops for-loop python-3.x while-loop

我需要编写一个程序:

  1. 要求开始帐户余额;
  2. 让我输入我的提款金额并循环这个问题,直到我输入0;和
  3. 告诉我帐户余额 - 无论是正面还是负面。
  4. 我遇到问题的主要区域:2。 - 撤回直到循环。

    示例输出:

    What is your starting balance: $ 1000.00
    What is your withdrawal amount: $ 250.00
    What is your withdrawal amount: $ 295.00
    What is your withdrawal amount: $ 187.50
    What is your withdrawal amount: $ 0
    Your account balance is: $267.50
    

1 个答案:

答案 0 :(得分:0)

#!/usr/bin/env python3.3

amt = int(input("What is your starting balance: $"))
while(True):
    i = int(input("What is your withdrawal amount: $"))
    if(i == 0):
        break
    else:
        amt -= i

print("Your account balance is:"+str(amt))
相关问题