In: Computer Science
By using the following:
-Python(you can use the filter function)
-Data class
-Functional Programming(don't use while & for loops but you can use if statement)
Write a program that reads table with given columns from input stream. Columns are name, amount, debt.(ONLY 3 columns, the person's first name and surname is under the column 'name'). Then filter the table (condition: debt is equal to 0). After that increase debt by 14% then output the results.
-----------------------------------------
Example.
User's Input:
3 - No. of People
Sam Hill 411889 36881
Angela Smith 121877 0
Nicholas Ander 783887 591951
Expected Output:
Sam Hill 411889 52371.02 Nicholas Ander 783887 840570.42
-----------------------------------------------------
NOTE: Don't use dataframes(panda,etc) and the code should enable user to input their details.
**Please also explain your answer*
HI,
Code is attached with Code Anippet.
Screenshot of the program to see the indentation and output images are attached.
from dataclasses import dataclass
#program is developed with using for loop or while loop
#program is developed with using Python dataclass class Person
n = int(input("How many ppl data you want to enter?"))
i=0
personList = []
@dataclass
class Person:
name: str
amount: float
debt: float
# this function taking multiple input from user based on number n and storing it in dataclass class Person class object
def iterate(num, start, end):
person = []
if start < 0 or start > end:
return
print("Please enter "+str(start)+" record of person out of "+str(end))
print("Please person name?")
pn = input()
print("Please amount?")
pa = float(input())
print("Please debt?")
pd = float(input())
pr = Person(pn,pa,pd)
personList.append(pr)
iterate(num, start + 1, end)
#iterate function to iterate list of Person dataclass and to display output which is required by you
def iterateDS(lst, start, end):
personlst = []
#print(end)
if start < 0 or start > end:
return
person = lst[start-1]
if(person.debt!=0):
per = (14/100)*person.debt
person.debt = person.debt+per
print(str(person.name)+" "+str(person.amount)+" "+str(person.debt)+"\n")
iterateDS(lst, start + 1, end)
# iterate to get input value from users with using for or while loop
iterate(n, 1,n)
print("\nProgram Updated Output\n")
print("Name Amount Debt")
#iterate to list of dataset Personby without using for loop or while loop
iterateDS(personList, 1, len(personList))
#print(personList)
.
Output screen: