2016-11-11 86 views
0

我對Python很陌生,所以我想知道是否有人可以幫我弄清我的while循環和break語句。while和break語句python 2.7

我可以讓它繼續或中斷,但從來都沒有。

我研究了這個主題,發現我發現的所有例子都傾向於數字等,或者提供的信息只是不點擊我。

所以,任何幫助,將不勝感激。

此計劃旨在計算您的每週工資。

而真:

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 
+4

'raw_input'返回一個字符串,而不是「真」/「假」。 –

+0

還有怎麼了你的空打印報表? –

+0

無論何時我在輸入行的末尾添加「\ n」,它都會停止工作,所以我隨空着的打印文件一起使它變得不那麼混亂。 –

回答

1

打破,如果應該是:

if cont == "": 

或數值告訴出境的用戶,所以:

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

可能想要解釋raw_input返回的內容以及爲什麼比較不同的對象不起作用 – MooingRawr

+1

ok iv嘗試了您的建議並設法使其運行,並且清空了空白打印選項等等。 –

+0

@MooingRawr在編輯中做了這些,但失去了連接:S Darren,基本上raw_input返回一個字符串,即使空仍然存在。 – Mixone