while和Break语句为python 2.7

时间:2016-11-11 18:12:50

标签: python if-statement while-loop break

我对python很新,所以我想知道是否有人可以帮我弄清楚我的while循环和break语句。

我可以继续或休息,但绝不会两者兼而有之。

我研究了这个主题,发现我发现的所有例子都是数字等等,或者所提供的信息都没有点击给我。

所以任何帮助都会受到赞赏。

此计划旨在计算您的每周工资。

而True:

Hours_Worked = int(raw_input("How many hours have you worked this week?:\n"))#This line of code allows the user to input the amount of hours they have worked in whole numbers only.


Hourly_Rate = float(raw_input("What is your hourly rate?:\n" u"\u00A3"))#This line of code allows the user to input their hourly rate of pay in floating numbers to wither a whole or decimal points.


Tax = int(raw_input("What is your current Tax rate?:\n" u"\u0025"))#This line of code allows the user to input their tax rate.


Nat = int(raw_input("What is your National Insurance rate?:\n" u"\u0025"))#This line of code allows the user to input their National Insurance rate.


Total_Weekly_Pay = (Hours_Worked*Hourly_Rate)#This line of code works out the weekly pay before deductions.


Total_Weekly_Pay_After_Deductions = Total_Weekly_Pay - (Tax*Total_Weekly_Pay/100) - (Nat*Total_Weekly_Pay/100)# This line of code works out the weekly pay after deductions. The Tax and National Insurance rate are worked out by multiplying and then dividing.


print "Your Total weekly pay before deductions is\n" u"\u00A3%5.2f" %(Total_Weekly_Pay)#This line of code prints out the weekly pay before deductions to the floating points of 5.2.


print "Your Total weekly pay after Tax and National Insurance deductions is\n" u"\u00A3%5.2f" %(Total_Weekly_Pay_After_Deductions)#This line of code prints out the weekly pay after deductions to the floating points of 5.2.

cont = raw_input("Would you like to try again? (yes/no)\n")
if cont == "no":
    print "Goodbye"
    break

1 个答案:

答案 0 :(得分:1)

如果应该是:

if cont == "":

或者告诉用户退出的值,所以:

cont = raw_input("Would you like to try again?  (Yes/No")
if cont == "No":