首页 > 解决方案 > 如果他使用Python输入的数据不正确,我如何让用户输入另一个响应

问题描述

我是初学者,我正在学习如何使用 Python。我正在编写与销售佣金有关的代码。销售经理需要计算支付给员工的佣金金额以及哪些员工将获得奖金。佣金基于他们出售的房产数量。房产中介每周有两到五名员工工作。

我已经在帮助下完成了大部分代码,并且所有代码都运行良好。该程序的作用是:询问那里的五名员工姓名、身份证和他们已售出的房产数量。然后在代码的最后计算每个员工的佣金,从高到低排列,佣金最高的员工获得 15% 的奖金。

如果他输入的数据不正确,我需要帮助的只是询问 2 到 5 之间的每个员工是否要使用“是或否”选项再次输入提交。并创建一个数据条目以查看数据是否正确。如果员工数据不正确,我需要帮助循环它,以便员工可以再次正确输入数据。这应该允许我在员工 2 到 5 之后提出问题。这是我被要求做的要求。

namearray = []
IDarray = []
carray = []
ASarray = []
repeatarray = []
dataEntry = True
entryCount = 0 
while dataEntry == True:
  name = input("Please enter the employee's name:")
  ID = input("Please enter your employee ID:")
  amountsold = int(input("Please enter the amount of properties sold:"))
  commission = amountsold*500
  ASarray.append(amountsold)
  namearray.append(name)
  IDarray.append(ID)
  carray.append(commission)
  entryCount +=1
  if entryCount == 5:
          dataEntry = False 
  elif entryCount > 1:
  
maxpos = carray.index(max(carray))
highestc = carray[maxpos]
highestname =  namearray[maxpos]
highestID = IDarray[maxpos]
mostsold = ASarray[maxpos]
bonus = int(highestc)*0.15
for i in range(0,len(carray)):
  print(namearray[i],"has a comission of",carray[i])
print ("The highest earner is",highestname,"who has sold",mostsold,"properties and has recieved a bonus of :",bonus)

ans = sum(carray) + bonus
print("Total commission paid: ",ans)
ans2 = sum(ASarray)
print("Total properties sold:" ,ans2)

标签: pythonpython-3.xpython-3.9

解决方案


推荐阅读