Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python错误计算程序_Python_Loops - Fatal编程技术网

Python错误计算程序

Python错误计算程序,python,loops,Python,Loops,要求用户输入公司的工资单信息。设置一个循环,继续询问信息,直到他们输入“完成”。针对每位员工,提出三个问题: 姓名(第一名和最后一名) 本周工作小时数(仅允许1到60小时) 小时工资(仅允许6.00至20.00) 验证工时和小时工资,并确保输入了名称 计算每个员工的工资,并将其写入连续文件。确保包含文件I/O错误处理逻辑 只包括周薪 周薪计算如下: (1-40小时)为小时费率*工作小时数 (41-60小时)为(工作小时数-40)*(小时费率*1.5) +每小时费率*40 输入所有员工后,在顺序文

要求用户输入公司的工资单信息。设置一个循环,继续询问信息,直到他们输入“完成”。针对每位员工,提出三个问题:

姓名(第一名和最后一名) 本周工作小时数(仅允许1到60小时) 小时工资(仅允许6.00至20.00) 验证工时和小时工资,并确保输入了名称

计算每个员工的工资,并将其写入连续文件。确保包含文件I/O错误处理逻辑

只包括周薪 周薪计算如下: (1-40小时)为小时费率*工作小时数 (41-60小时)为(工作小时数-40)*(小时费率*1.5) +每小时费率*40

输入所有员工后,在顺序文件中将每个员工的周工资读入名为“支付”的列表。对列表进行排序。现在打印本周最低、最高和平均周工资

我对这个代码有明显的问题

while len(eName)>0:
     eName=raw_input("\nPlease enter the employees' first and last name. ")
     hWork=raw_input("How many hours did they work this week? ")
     hoursWork=int(hWork)
     if hoursWork < 1 or hoursWork > 60:
         print "Employees' can't work less than 1 hour or more than 60 hours!"

     else:
         pRate=raw_input("What is their hourly rate? ")
         payRate=int(pRate)
         if payRate < 6 or payRate > 20:
              print "Employees' wages can't be lower than $6.00 or greater than $20.00!"
         if hoursWork <=40:
              grossPay=hoursWork*payRate
         else:
              grossPay=((hoursWork-40)*(payRate*1.5))+(40*payRate)
         lsthours.append(grossPay)
     print grossPay
     print lsthours



     ePass=raw_input("Type DONE when finished with employees' information. ")
     ePass.upper() == "DONE"
     if ePass == "DONE":
          break
     else:
          continue
而len(eName)>0:
eName=原始输入(“\n请输入员工的名字和姓氏。”)
hWork=原始输入(“他们本周工作了多少小时?”)
工时=int(工时)
如果工时<1小时或工时>60小时:
打印“员工不能工作少于1小时或超过60小时!”
其他:
pRate=原始输入(“他们的小时费率是多少?”)
工资率=整数(普拉特)
如果工资率<6或工资率>20:
打印“员工工资不能低于$6.00或高于$20.00!”

如果hoursWorkYu可以这样做:

grossPay = 0.0
lsthours = []

eName=raw_input("\nPlease enter the employees' first and last name (type 'PASS' to  exit): ") 

while eName.upper() != "PASS":      
   hWork=raw_input("How many hours did they work this week? ") 
   hoursWork=int(hWork)

   if hoursWork < 1 or hoursWork > 60: 
      print "Employees' can't work less than 1 hour or more than 60 hours!" 
   else: 
      pRate=raw_input("What is their hourly rate? ") 
      payRate=int(pRate) 

      if payRate < 6 or payRate > 20: 
         print "Employees' wages can't be lower than $6.00 or greater than $20.00!" 

      if hoursWork <=40: 
         grossPay=hoursWork*payRate 
      else: 
         grossPay=((hoursWork-40)*(payRate*1.5))+(40*payRate) 

      lsthours.append(grossPay) 

      print grossPay 
      print lsthours 

  eName=raw_input("\nPlease enter the employees' first and last name. (type 'PASS' to exit): ")
grossPay=0.0
lsthours=[]
eName=原始输入(“\n请输入员工的名字和姓氏(键入“通过”退出):”)
而eName.upper()!=“通行证”:
hWork=原始输入(“他们本周工作了多少小时?”)
工时=int(工时)
如果工时<1小时或工时>60小时:
打印“员工不能工作少于1小时或超过60小时!”
其他:
pRate=原始输入(“他们的小时费率是多少?”)
工资率=整数(普拉特)
如果工资率<6或工资率>20:
打印“员工工资不能低于$6.00或高于$20.00!”

如果hoursWorkYu可以这样做:

grossPay = 0.0
lsthours = []

eName=raw_input("\nPlease enter the employees' first and last name (type 'PASS' to  exit): ") 

while eName.upper() != "PASS":      
   hWork=raw_input("How many hours did they work this week? ") 
   hoursWork=int(hWork)

   if hoursWork < 1 or hoursWork > 60: 
      print "Employees' can't work less than 1 hour or more than 60 hours!" 
   else: 
      pRate=raw_input("What is their hourly rate? ") 
      payRate=int(pRate) 

      if payRate < 6 or payRate > 20: 
         print "Employees' wages can't be lower than $6.00 or greater than $20.00!" 

      if hoursWork <=40: 
         grossPay=hoursWork*payRate 
      else: 
         grossPay=((hoursWork-40)*(payRate*1.5))+(40*payRate) 

      lsthours.append(grossPay) 

      print grossPay 
      print lsthours 

  eName=raw_input("\nPlease enter the employees' first and last name. (type 'PASS' to exit): ")
grossPay=0.0
lsthours=[]
eName=原始输入(“\n请输入员工的名字和姓氏(键入“通过”退出):”)
而eName.upper()!=“通行证”:
hWork=原始输入(“他们本周工作了多少小时?”)
工时=int(工时)
如果工时<1小时或工时>60小时:
打印“员工不能工作少于1小时或超过60小时!”
其他:
pRate=原始输入(“他们的小时费率是多少?”)
工资率=整数(普拉特)
如果工资率<6或工资率>20:
打印“员工工资不能低于$6.00或高于$20.00!”

如果hoursWork此代码有几个问题:

  • 压痕到处都是。例如,while循环在第一个if语句处结束
  • while循环的测试几乎肯定是错误的(因为eName没有初始化),所以循环永远不会进入
  • ePass.upper()=“DONE”处的代码正在尝试设置ePass变量,这意味着测试将无法工作。你需要:

    如果ePass.upper()=“完成”: 中断


此代码有几个问题:

  • 压痕到处都是。例如,while循环在第一个if语句处结束
  • while循环的测试几乎肯定是错误的(因为eName没有初始化),所以循环永远不会进入
  • ePass.upper()=“DONE”处的代码正在尝试设置ePass变量,这意味着测试将无法工作。你需要:

    如果ePass.upper()=“完成”: 中断


已经指出的一些错误:

在python中,缩进决定代码块

while循环:

while logic_test:
    # this is inside while loop
    ....
# this is outside while loop
字符串上的某些函数不会替换原来的字符串,它们通过返回值返回另一个字符串

上:

>>> a = "done"
>>> a.upper()
'DONE'
>>> a
'done'
>>> 
始终初始化变量。

如果您使用的是sequence方法,那么之前应该将变量定义为sequence

>>> t.append('ll')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 't' is not defined
>>> t = []
>>> t.append('ll')
>>> 

已经指出的一些错误:

在python中,缩进决定代码块

while循环:

while logic_test:
    # this is inside while loop
    ....
# this is outside while loop
字符串上的某些函数不会替换原来的字符串,它们通过返回值返回另一个字符串

上:

>>> a = "done"
>>> a.upper()
'DONE'
>>> a
'done'
>>> 
始终初始化变量。

如果您使用的是sequence方法,那么之前应该将变量定义为sequence

>>> t.append('ll')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 't' is not defined
>>> t = []
>>> t.append('ll')
>>> 
试试这个:

lsthours = list()
eName = "start" # initialize to something to start the loop
while eName:
    eName = raw_input("\nPlease enter the employees' first and last name. ")
    if not eName:
        break #loop will exit also when blank name is inserted
    hWork = raw_input("How many hours did they work this week? ")
    hoursWork = int(hWork)
    if hoursWork < 1 or hoursWork > 60:
        print "Employees' can't work less than 1 hour or more than 60 hours!"
        continue #skip

    pRate = raw_input("What is their hourly rate? ")
    payRate = int(pRate)
    if payRate < 6 or payRate > 20:
        print "Employees' wages can't be lower than $6.00 or greater than $20.00!"
        continue #skip
    if hoursWork <= 40:
        grossPay = hoursWork * payRate
    else:
        grossPay = ((hoursWork - 40) * (payRate * 1.5)) + (40 * payRate)
    lsthours.append(grossPay)
    print grossPay
    print lsthours
    ePass = raw_input("Type DONE when finished with employees' information. ")
    if ePass.upper() == "DONE":
        break
lsthours=list()
eName=“start”#初始化为某个值以启动循环
而珐琅:
eName=原始输入(“\n请输入员工的名字和姓氏。”)
如果不是eName:
插入空白名称时,也将退出中断#循环
hWork=原始输入(“他们本周工作了多少小时?”)
工时=int(工时)
如果工时<1小时或工时>60小时:
打印“员工不能工作少于1小时或超过60小时!”
继续#跳过
pRate=原始输入(“他们的小时费率是多少?”)
工资率=整数(普拉特)
如果工资率<6或工资率>20:
打印“员工工资不能低于$6.00或高于$20.00!”
继续#跳过
如果工作时间请尝试以下方法:

lsthours = list()
eName = "start" # initialize to something to start the loop
while eName:
    eName = raw_input("\nPlease enter the employees' first and last name. ")
    if not eName:
        break #loop will exit also when blank name is inserted
    hWork = raw_input("How many hours did they work this week? ")
    hoursWork = int(hWork)
    if hoursWork < 1 or hoursWork > 60:
        print "Employees' can't work less than 1 hour or more than 60 hours!"
        continue #skip

    pRate = raw_input("What is their hourly rate? ")
    payRate = int(pRate)
    if payRate < 6 or payRate > 20:
        print "Employees' wages can't be lower than $6.00 or greater than $20.00!"
        continue #skip
    if hoursWork <= 40:
        grossPay = hoursWork * payRate
    else:
        grossPay = ((hoursWork - 40) * (payRate * 1.5)) + (40 * payRate)
    lsthours.append(grossPay)
    print grossPay
    print lsthours
    ePass = raw_input("Type DONE when finished with employees' information. ")
    if ePass.upper() == "DONE":
        break
lsthours=list()
eName=“start”#初始化为某个值以启动循环
而珐琅:
eName=原始输入(“\n请输入员工的名字和姓氏。”)
如果不是eName:
插入空白名称时,也将退出中断#循环
hWork=原始输入(“他们本周工作了多少小时?”)
工时=int(工时)
如果工时<1小时或工时>60小时:
打印“员工不能工作少于1小时或超过60小时!”
继续#跳过
pRate=原始输入(“他们的小时费率是多少?”)
工资率=