如何重写依赖于两个变量的变量?



嗨,我需要对以下问题进行编码:

";如果一名员工在公司工作超过一年,他们在公司工作的每一年都可以享受7天的假期。否则,他只会悲痛欲绝两天。此外,如果员工每周额外工作超过10小时,他们每工作10小时就会有2天的假期">

到目前为止,我有以下代码,但当我做最后的数学运算时,它不会给出我应该得到的确切结果,所以我不知道是否有办法解决它。此外,是否可以使用elif和布尔表达式重写此代码?

vacations = 0 
print("Enter Employee Experience in the company") 
years = int(input("Years : ")) 
for i in range(years+1):
if years < 1:
vacations = vacations + 2
else:
vacations = vacations + 7
years = years - 1

ex_hours = int(input("Extra Hours Worked : ")) 
while(ex_hours >= 10 ):
vacations = vacations + 2
ex_hours = ex_hours -10
print("The Employee is eligible for ",vacations," days vacation")

您根本不需要循环。每一步只需进行一次计算。

vacations = 0 
print("Enter Employee Experience in the company") 
years = int(input("Years : ")) 
if years > 1:
vacations = years * 7
else:
vacations = 2
ex_hours = int(input("Extra Hours Worked : "))
vacations = vacations + (ex_hours // 10) * 2
print("The Employee is eligible for ",vacations," days vacation")

最新更新