如果他们拒绝

时间:2018-03-16 21:21:06

标签: python-3.x

print ("Welcome to my Break-even calculator")
FC = input("Please enter your fixed costs ")
SP = input("Please enter your Selling Price (per item) ")
VC = input("Please enter your Variable costs (per item) ")
A = float(SP) - float(VC)
BE = float(FC) / A
print("Your Break-even point is ",BE)
B = input("Would you like to go again y/n? ")
while B not in ['y','n']:
    print("INVALID RESPONCE")
    B = input("Would you like to go again y/n? ")
if B == ("y"):
    FC = input("Please enter your fixed costs ")
    SP = input("Please enter your Selling Price (per item) ")
    VC = input("Please enter your Variable costs (per item) ")
    A = float(SP) - float(VC)
    BE = float(FC) / A
    print("Your Break-even point is ", BE)
    B = input("Would you like to go again y/n? ")
else:
    finished = True

我在学校,每次都无法进行计算,所以我写了这个,但我不能重复两次以上,所以我想知道我需要改变什么来让它工作所以任何帮助将是好的。

1 个答案:

答案 0 :(得分:0)

让程序无限期地运行(好吧,直到他们说不),这是最好的方法:使用while循环:

running = True

while running:
    [all your code here]

然后,当用户说“n”时,您可以执行以下操作:

if B (your yes/no var?) == 'n':
    running = False

这会立即停止while循环。希望这会有所帮助。