我遇到了一个python类的第一个程序问题。这应该取三个值,这两个值用两种不同的函数计算(一个和一个没有奖励)。然后我想在主函数中输出所有的结果。正如您所看到的,我在正确打印结果时遇到问题。如果我输入一些将返回工资,奖金,基数,工作月数和佣金的变量,如果月工作> 3,我应该得到所有这些变量,如果月工作时没有奖金< 3.它也应该减去或增加额外基于其他两个if语句的值。Python程序不会返回值奖金
#calculate income rates with sales, bonus, comission
def income(sales):
if (sales > 1000000):
bonus = 100000
commission = .35
salary = 2000 + sales + bonus + (sales * commission)
elif(sales >= 500001 and sales <= 1000000):
bonus = 5000
commission = .28
salary = 2000 + sales + bonus + (sales * commission)
elif (sales >= 100001 and sales <= 500000):
bonus = 1000
commission = .15
salary = 2000 + sales + bonus + (sales * commission)
elif (sales >= 10000 and sales <= 100000):
bonus = 0
commission = .02
salary = 2000 + sales + bonus + (sales * commission)
else:
bonus = 0
commission = 0
salary = 2000 + sales + bonus + (sales * commission)
return salary
return bonus
return commission
#calculate income rates with sales and commission, no bonus
def calc_no_bonus(sales):
bonus = 0
if (sales > 1000000):
commission = .35
salary = 2000 + sales + (sales * commission)
elif(sales >= 500001 and sales <= 1000000):
commission = .28
salary = 2000 + sales + (sales * commission)
elif (sales >= 100001 and sales <= 500000):
commission = .15
salary = 2000 + sales + (sales * commission)
elif (sales >= 10000 and sales <= 100000):
commission = .02
salary = 2000 + sales + (sales * commission)
else:
commission = 0
salary = 2000 + sales + (sales * commission)
return salary
return commission
def main():
name = input("What is your name? ")
sales = float(input("Input your annual sales: "))
vacation = int(input("How many vacation days have you taken? "))
months = int(input("How many years have you been with the company? Please enter in number of months: "))
base = 2000
salary = 0
bonus= 0
commission = 0
if (months < 3):
salary = calc_no_bonus(sales)
else:
salary = income(sales)
bonus = income(bonus)
commission = income(commission)
#For salespeople who have been with the company for more than 5 years and who have made sales greater than $100,000 an additional bonus of $1000 is added
if (months > 60 and sales > 100000):
salary = income(sales) + 1000
#If a salesperson has taken more than 3 vacation days in a month, their pay gets reduced
#by $200
if (vacation > 3):
salary = income(sales) - 200
print("Your total salary is $", format(salary, ',.2f'), sep='')
print("This consists of: \n your sales of $", format(sales, ',.2f'), sep='')
print("your base of $", base)
print("your bonus of $", bonus)
print("your commission of $", commission)
main()
结果:
What is your name? j
Input your annual sales: 1000000
How many vacation days have you taken? 6
How many years have you been with the company? Please enter in number of months: 2
Your total salary is $1,286,800.00
This consists of:
your sales of $1,000,000.00
your base of $ 2000
your bonus of $ 0
your commission of $ 0
What is your name? j
Input your annual sales: 1000000
How many vacation days have you taken? 8
How many years have you been with the company? Please enter in number of months: 4
Your total salary is $1,286,800.00
This consists of:
your sales of $1,000,000.00
your base of $ 2000
your bonus of $ 2000
your commission of $ 2000
The syntax of salary:
1,000,000 sales
350,000 comission
100,000 bonus
2,000 base
salary should be 1,452,000?
当我试图改变我的返回语句,就像我得到这个错误:ypeError:不支持的操作数类型为 - :'tuple'和'int' –
现在结果关闭: –
你叫什么名字? julie 输入您的年销售额:1000000 您已经度过了多少个假期? 5 你在公司工作多少年了?请在号码中输入月:5 您的总薪水为$ 1,287,000.00 这包括: 您的$ 1,000,000.00 销售的$ 2000 基地您的$奖金(7000,0,0) 您的$佣金(2000.28, 0,0) >>> –