python - 如果他使用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)
解决方案
推荐阅读
- amazon-web-services - 按距离排序查询需要读取整个数据集?
- oracle-apex - Apex 数据加载:来自 csv 文件的 2 个数字列根据条件选择 1 并加载到表中
- java - 如何使前端 angularjs 代码与同一 EC2 上的后端 java 代码通信
- python - 如何在拆分之前避免同时包含字符串和数字的行?
- javascript - Vue + Webpack - 指定服务器进行热重载
- python - 使用 [import package] 而不是 [from package import package] 设置 python
- android - Android - SharedPreferences - 根据偏好值调整代码?
- sql-server - 将历史表转换为时态表
- android - 如何解决“违反使用 Android 广告 ID 政策和开发者分发协议第 4.8 节”的问题
- javascript - JavaScript 中的深度对象比较和属性定位