Калькулятор ежедневных процентов, который должен кредитовать ежемесячно с учетом различных пользовательских входов - PullRequest
0 голосов
/ 14 марта 2019

Я новичок в программировании и последние несколько дней работаю над тем, чтобы выучить Python.Я пытаюсь создать программу, которая рассчитывает ежедневные проценты и проценты по кредитам ежемесячно с учетом пользовательских входов.

Хорошо: программа может добавлять депозиты к первоначальному балансу каждые 14 дней, как я хотел.Программа может определить, является ли ввод високосным годом или нет.Программа способна определять ежедневные проценты.

Плохо: я не смог выяснить, как заставить программу суммировать рассчитанные ежедневные проценты за данный месяц, а затем добавить ее к начальному балансуследующего месяца

import datetime
from datetime import date
from datetime import timedelta
import calendar
from decimal import Decimal
def gupta():
    print("Enter a start date in YYYY-MM-DD format")
    date_entry = input() #records account's start date as string
    year, month, day = map(int, date_entry.split('-')) #splits contents of date_entry string variable into separate integers thus rendering date1 variable actionable by datetime.date
    date1 = datetime.date(year, month, day) #records account's start date as datetime.date (module?)
    print("Enter an end date in YYYY-MM-DD format") 
    date_entry = input() #records account's end date as string
    year, month, day = map(int, date_entry.split('-')) #splits contents of date_entry string variable into separate integers thus rendering date1 variable actionable by datetime.date
    date2 = datetime.date(year, month, day) #records account's end date as datetime.date (module?)
    print("The starting date is " + str(date1) + " and the ending date is " + str(date2))
    print("Enter your initial balance")
    initial_balance = Decimal(input()) #requests initial balance (assumes this is amount to be deposited every 14 days)
    print("Enter your interest rate (as a decimal)")
    interest_rate = Decimal(input()) #records interest rate as a decimal
    date1 = date1.toordinal() #changes date1 to ordinal
    date2 = date2.toordinal() #changes date2 to ordinal
    list_interest = []
    for current_date in range(date1, date2 + 1): #cycles through date1 and date2 using a step/iteration of 1
        date_spread = current_date - date1
        new = current_date + 1
        print(date.fromordinal(current_date).strftime('%Y-%m-%d'))
        print(list_interest)
        if date_spread != 14: #checks to see whether additional deposit is going to be made
            current_date = date.fromordinal(current_date)
            new = date.fromordinal(new)
            current_date_y = str(current_date.strftime("%Y"))
            new_m = str(new.strftime("%m"))
            current_date_m = str(current_date.strftime("%m"))
            current_balance = initial_balance + 0
            print(current_balance)
            if calendar.isleap(int(current_date_y)):
                daily_interest = round(current_balance * (interest_rate / 366), 2)
                print(daily_interest)
                if current_date_m == new_m: 
                    list_interest.append(daily_interest)
                    print(list_interest)
            else:
                daily_interest = round(current_balance * (interest_rate / 365), 2)
                print(daily_interest)
                if current_date_m == new_m: 
                    list_interest.append(daily_interest)
                    print(list_interest)
            current_date = date.toordinal(current_date)
        elif date_spread == 14: #checks to see whether additional deposit is going to be made      
            current_date = date.fromordinal(current_date)
            new = date.fromordinal(new)
            current_date_y = str(current_date.strftime("%Y"))
            new_m = str(new.strftime("%m"))
            current_date_m = str(current_date.strftime("%m"))
            current_balance = initial_balance + 150
            initial_balance = current_balance
            print(current_balance)
            if calendar.isleap(int(current_date_y)):
                daily_interest = round(current_balance * (interest_rate / 366), 2)
                print(daily_interest)
                if current_date_m == new_m: 
                    list_interest.append(daily_interest)
                    print(list_interest) 
            else:
                daily_interest = round(current_balance * (interest_rate / 365), 2)
                print(daily_interest)
                if current_date_m == new_m: 
                    list_interest.append(daily_interest)
                    print(list_interest)    
            current_date = date.toordinal(current_date)
            new = date.toordinal(new)
            date1 = current_date
            list_interest = []
    #print(current_balance)
...