我遇到了一個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) >>> –