找到所有变量的总和?
问题描述:
试图找到一种方法来找到总体基本工资,总佣金和全部支付给该部门所有员工的问题。到目前为止,我有这样的代码:找到所有变量的总和?
employee = str(1)
numbemployee = input('How many employees are there in your department? ')
while numbemployee < str(0):
print('The number of employees cannot be less than zero!')
numbemployee = int(input('How many employees are there in your department? '))
while employee <= numbemployee:
name = str(input('What is the name of employee ' +employee +'? '))
employee = str(int(employee) + 1)
totalyears = int(input('How many years has ' +name +' worked for the company? '))
while totalyears < 0:
print('The number of years worked cannot be less than zero!')
totalyears = int(input('How many years has ' +name +' worked for the company? '))
if totalyears <= 6:
base_salary = 10000.00
print('The base salary for ' ,name ,' should be $' ,base_salary)
elif totalyears <= 13:
base_salary = 14000.00
print('The base salary for ' ,name ,' should be $' ,base_salary)
elif totalyears <= 20:
base_salary = 18000.00
print('The base salary for ' ,name ,' should be $' ,base_salary)
elif totalyears <= 34:
base_salary = 27000.00
print('The base salary for ' ,name ,' should be $' ,base_salary)
else:
base_salary = 30000.00
print('The base salary for ' ,name ,' should be $' ,base_salary)
sales = float(input('What was ' +name +"'s sales for the last quarter? "))
while sales < 0:
print('The sales cannot be less than zero!')
sales = float(input('What was ' +name +"'s sales for the last quarter? "))
if sales <= 3999.99:
commission = 1000
print(name ,'earned $' ,commission ,'from commission for sales from last quarter')
elif sales <= 11999.99:
commission = 2000
print(name ,'earned $' ,commission ,'from commission for sales from last quarter')
elif sales <= 15999.99:
commission = 5000
print(name ,'earned $' ,commission ,'from commission for sales from last quarter')
elif sales <= 23999.99:
commission = 8000
print(name ,'earned $' ,commission ,'from commission for sales from last quarter')
elif sales <= 27999.99:
commission = 12000
print(name ,'earned $' ,commission ,'from commission for sales from last quarter')
else:
commission = 15000
print(name ,'earned $' ,commission ,'from commission for sales from last quarter')
totalwage = base_salary + commission
print(name ,'should recieve $' ,totalwage ,' for this quarter.')
我无法找到部门中所有员工的总基薪。所有员工的总佣金和全部工资都相同。有谁知道我会怎么做?
答
你有一堆问题与你的代码 - 这很好,这显然是一个学习问题。
为了总结所有基本工资,奖金等,您将必须创建一个累加器这些和的变量。现在,你有员工细节的变量。您需要添加一些更变量从一个员工处理累积总数下一:
accum_total_salary = 0
accum_total_commission = 0
while ...
base_salary = ...
commission = ...
accum_total_salary += base_salary
accum_total_commission += commission
最后,外循环,当你处理完所有工作信息,您可以打印您的累积数字:
print("Sum total salary paid to all employees:", accum_total_salary)
print("Sum total commission paid to all employees:", accum_total_commission)
+0
代码无法正常工作的很大一部分是错误地将东西转换为应该是数字的“str”。 – roganjosh
为什么你将你的输入转换为int,然后将它与'str(0)'比较?也可以考虑把'雇员'变成一个班级或至少一本字典...... – MooingRawr
这个“问题”需要进一步完善。你想做什么?什么是伪代码?发生了什么,你不指望? – Nathan
可以通过一个简单的例子和解释你尝试过的东西来把它变成一个有用的问题。请参阅http://stackoverflow.com/help/mcve – chadnt