晚上好!我是一名律师,我经常要计算被判刑的人能够获得假释等福利的时间
它的工作原理如下:
首先,我需要得到一些主要变量,比如那个人开始服刑的那天(他被捕的那天)。这将是第一项福利的基准日期。假设2014年11月12日有人被捕
base_date = datetime.date(day=12, month=11, year=2014)
我必须做的第二件事是知道每一项罪行的刑罚(有时此人被判犯有不止一项罪行,对于每一项罪行,都有不同的利益计算。假设此人被判犯有两项罪行:
为了做到这一点,我使用了这个方法,这就是我认为我的代码失败的地方。我相信这些变量应该在datetime方法中,或者类似的方法中
pena1_years, pena1_months, pena1_days = 7, 4, 0
pena2_years, pena2_months, pena2_days = 4, 10, 20
现在,由于第一次犯罪更严重,他需要服刑五分之二加上第二次服刑的六分之一才能获得第一次利益。两次服刑的结果都应该加在基准日上,以便知道他何时能够获得第一次利益。我把一切都变成了几天
pena1_total = int(((pena1_years * 365) + (pena1_months * 30) + (pena1_days)) / 5 * 2)
datedifference1 = datetime.datetime.now() - datetime.timedelta(days=pena1_total)
pena1_total = relativedelta(datetime.datetime.now(), datedifference1)
print("Pena 1: " + str(pena1_total.years) + "a, " + str(pena1_total.months) + "m, " + str(pena1_total.days) + "d.")
(打印返回:Pena 1:2a、11m、4d。)
pena2_total = int(((pena2_years * 365) + (pena2_months * 30) + (pena2_days)) / 6)
datedifference2 = datetime.datetime.now() - datetime.timedelta(days=pena2_total)
pena2_total = relativedelta(datetime.datetime.now(), datedifference2)
print("Pena 2: " + str(pena2_total.years) + "a, " + str(pena2_total.months) + "m, " + str(pena2_total.days) + "d.")
(打印返回此:Pena 2:0a、9m、21d。)
在计算完每一项犯罪的分数后,我需要将两者相加,然后加上基准日期。在这种情况下,这家伙第一次犯罪要服刑2年11个月零5天,第二次犯罪要服刑9个月零23天,总共服刑3年8个月零29天,他才能获得第一笔福利。然而,我需要遵循此规则(法律规定必须计算):
我就是这样做的,但我不会得到2018年8月9日:
total = pena1_total + pena2_total
print("Total: " + str(total.years) + "a, " + str(total.months) + "m, " + str(total.days) + "d.")
(打印返回:总计:3a、8m、25d)
data_semiaberto = data_base + relativedelta(days=+total.days, months=+total.months, years=+total.years)
print("Data para o semiaberto: " + str(data_semiaberto))
(打印返回:数据段o semiaberto:2018-08-06)
然后,第一次受惠的日期将是他假释的基准日期。他将需要为第一次犯罪的剩余刑期再服2/5,为第二次犯罪的剩余刑期再服1/6。为此,我需要从每一次犯罪的总刑期中减去他迄今为止所服的刑期。然而,我被困在这里
以下是完整的代码:
import datetime
from dateutil.relativedelta import relativedelta
data_base = datetime.date(day=12, month=11, year=2014)
pena1_years, pena1_months, pena1_days = 7, 4, 0
pena2_years, pena2_months, pena2_days = 4, 10, 20
def calculadora():
# Fraction of the first sentence
pena1_total = int(((pena1_years * 365) + (pena1_months * 30) + (pena1_days)) / 5 * 2)
datedifference1 = datetime.datetime.now() - datetime.timedelta(days=pena1_total)
pena1_total = relativedelta(datetime.datetime.now(), datedifference1)
print("Pena 1: " + str(pena1_total.years) + "a, " + str(pena1_total.months) + "m, " + str(pena1_total.days) + "d.")
# Fraction of the second sentence
pena2_total = int(((pena2_years * 365) + (pena2_months * 30) + (pena2_days)) / 6)
datedifference2 = datetime.datetime.now() - datetime.timedelta(days=pena2_total)
pena2_total = relativedelta(datetime.datetime.now(), datedifference2)
print("Pena 2: " + str(pena2_total.years) + "a, " + str(pena2_total.months) + "m, " + str(pena2_total.days) + "d.")
# Fraction total
total = pena1_total + pena2_total
print("Total: " + str(total.years) + "a, " + str(total.months) + "m, " + str(total.days) + "d.")
# Date of the first benefit.
data_semiaberto = data_base + relativedelta(days=+total.days, months=+total.months, years=+total.years)
print("Data para o semiaberto: " + str(data_semiaberto))
calculadora()
有人能帮帮我吗?这样可以节省我很多工作时间
检查下面的代码,它首先计算天数,然后减去每个福利的天数,并打印下一个福利可用日期的日期
要考虑每个月的闰年和天数,最好计算总天数并建立它的逻辑。输出将打印每个福利的详细信息,并最终显示在一起的总天数
既然我是来学习的,我想试试这个。这段代码仍然需要一些工作,但我认为这是一个良好的开端。如果你抛弃它,我的感情不会受到伤害。如果您想使用,我们可以根据需要添加功能
通过阅读Rickey和Sathish的答案,我想出了一个解决方案。它返回了正确的日期
仍然需要完成代码以自动化任何情况
我不确定是否可以在这里发布GitHub。这是代码
相关问题 更多 >
编程相关推荐