这是我试图做的代码,但它不会按照我想要的方式进行计算,我想返回e1,e2和e3中的最小值
def hra_exemption_calc():
#Variables
city1 = 'Delhi'
city2 = 'Kolkata'
city3 = 'Chennai'
city4 = 'Mumbai'
e1 = 0
e2 = 0
e3 = 0
exemption = 0
#Criterias
place = str(input('Enter your place of employment: '))
basic = int(input('Enter your basic salary: '))
rent = int(input('Enter your rent for an year: '))
#Calculation
if rent > 0.1 * basic:
return e1 == 0.1 * basic
if place := [city1,city2,city3,city4]:
return e2 == 0.5 * basic
else:
return e2 == 0.4 * basic
e3 = rent
#Finding the least exemption
exemption = min(e1,e2,e3)
首先,要将值赋给变量(例如e1, e2和e3),您应该使用单个等号(=
)。你应该计算你的三个变量,然后用min
函数取最小值并返回它。
if rent > 0.1 * basic:
e1 = 0.1 * basic
if place := [city1,city2,city3,city4]:
e2 = 0.5 * basic
else:
e2 = 0.4 * basic
e3 = rent
#Finding the least exemption
exemption = min([e1,e2,e3])
return exemption
另外,我不确定您在if语句中使用:=
操作符做了什么,这只会创建一个名为place
的新变量,并且该语句始终为True
。