Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions simple_intrest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@

import csv

Check failure on line 2 in simple_intrest.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (I001)

simple_intrest.py:2:1: I001 Import block is un-sorted or un-formatted
def get_int(prompt,low):

Check failure on line 3 in simple_intrest.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (ARG001)

simple_intrest.py:3:20: ARG001 Unused function argument: `low`

Check failure on line 4 in simple_intrest.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (W293)

simple_intrest.py:4:1: W293 Blank line contains whitespace
returnLoan=int(input(prompt))

Check failure on line 5 in simple_intrest.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (N806)

simple_intrest.py:5:5: N806 Variable `returnLoan` in function should be lowercase
return returnLoan
def get_float(prompt,low):

Check failure on line 7 in simple_intrest.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (ARG001)

simple_intrest.py:7:22: ARG001 Unused function argument: `low`

Check failure on line 8 in simple_intrest.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (W293)

simple_intrest.py:8:1: W293 Blank line contains whitespace
getFloat=float(input(prompt))

Check failure on line 9 in simple_intrest.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (N806)

simple_intrest.py:9:5: N806 Variable `getFloat` in function should be lowercase
return getFloat
def calculate_simple_interest(principle,interest_rate,year=1):
simpleInterest = principle*(interest_rate/100)*year

Check failure on line 12 in simple_intrest.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (N806)

simple_intrest.py:12:9: N806 Variable `simpleInterest` in function should be lowercase
return simpleInterest
def write_to_csv(file_name,data,col_separator):

Check failure on line 14 in simple_intrest.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (ARG001)

simple_intrest.py:14:33: ARG001 Unused function argument: `col_separator`
header=['Loan', 'Rate', 'Time', 'Interest']
with open(file_name,"w",newline='\n') as f:
writer=csv.writer(f)
writer.writerow(header)
writer.writerow(data)

Check failure on line 20 in simple_intrest.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (W293)

simple_intrest.py:20:1: W293 Blank line contains whitespace
def read_and_display(file_name,col_separator=","):
r=[]
with open(file_name,'r') as f:
csvreader=csv.reader(f)
flag=0
for row in csvreader:
if(flag==0):
flag=1
print(row,"\n")
else:
for rows in row:
s=''
l=[]
print(rows)
l=list(rows.split(","))
s="The interest on a loan of $"+str(l[0][1:])+" at "+str(l[1])+"% interest rate for "+str(l[2])+" yearsis $"+str(l[3][0:-1])+"."
r.append(s)

for i in r:
print(i)
f.close()


result=[]
while(True):
while(True):
principle=get_int("Please enter the amount of loan:",0)
if(principle<=0):
print("Entry must be an integer greater than 0 please try again")
else:
break
while(True):
interestRate=get_float("Please enter the interest rate:",0)
if(interestRate<0):
print("Entry must be a floating number greater than 0 Please try again")
else:
break
while(True):
year=get_int("Please enter the number of years:",0)
if(year<0):
print("Entry must be an integer greater than 0 Please try again")
else:
break
result.append([principle,interestRate,year,calculate_simple_interest(principle,interestRate,year)])

choice=input("Do you want to do another calculation? (y for yes)")
if(choice=='n'):

write_to_csv("simple.CSV",result,",")
break
read_and_display("simple.CSV",",")
Loading