python2.7的While和Break语句

2024-09-30 01:24:37 发布

您现在位置:Python中文网/ 问答频道 /正文

我对python比较陌生,所以我想知道是否有人能帮我弄清楚while循环和break语句。在

我可以让它继续或中断,但决不能两者兼而有之。在

我研究过这个主题,发现我找到的所有例子都是关于数字之类的,或者提供的信息并不是我想要的。在

因此,任何帮助都将不胜感激。在

这个计划是用来计算你的周工资的

如果是真的:

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

Tags: ofthetoinputrawratelinecode

热门问题