Question

In: Computer Science

By using the following: -Python(you can use the filter function) -Data class -Functional Programming(don't use while...

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*

Solutions

Expert Solution

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:


Related Solutions

Using Python programming language, write a LONG piece of code that utilizes the do while function...
Using Python programming language, write a LONG piece of code that utilizes the do while function and the switch statement, please do not make It short, thank you.
C++: Write the following function prototypes that would be declared for the Cplx class (you don't...
C++: Write the following function prototypes that would be declared for the Cplx class (you don't need to write the function definitions or write the rest of the class). Cplx class is a complex class with lots of data. Remember to show the return type, and const where needed. For all your parameters, call them lval or rval to show that you understand where they would be in the operation. // << function // + as a non-member function //...
Using python programming language, compare the four tasks. 1. For the following exercises you will be...
Using python programming language, compare the four tasks. 1. For the following exercises you will be writing a program that implements Euler’s method (pronounced ‘oy-ler’). It may be the case that you have not yet encountered Euler’s method in the course. Euler’s method can be found in Chapter 10.2 of your notes, which gives a good description of why this algorithm works. But for our purposes, we only need to know the algorithm itself - so there’s no need to...
Code in Python. You can only use while loops NOT for loops. Program 1: cost_living In...
Code in Python. You can only use while loops NOT for loops. Program 1: cost_living In 2020 the average cost of living/month (excluding housing) for a family of 4 in Pittsburgh was $3850 per month. Write a program to print the first year in which the cost of living/month is over $4450 given that it will rise at a rate of 2.1% per year. (Note:  this program requires no input). Program 2: discount A discount store is having a sale where...
Cryptography - please use Python to complete the following task. You don't have to implement AES...
Cryptography - please use Python to complete the following task. You don't have to implement AES just import the necessary libraries. Can you fix my code? Thanks! Read in a 128 bit key from the user (16 characters). If the user enters a key of any other size it's fine to terminate the program with an error. Read in a string of arbitary length from the user. (ie, the string could be 1 character, or 50,000, or anywhere in between)....
convert this code to Python and make sure you use chained map and filter as well....
convert this code to Python and make sure you use chained map and filter as well. https://book.pythontips.com/en/latest/map_filter.html CODE BELOW IS IN JAVASCRIPT let people = [ {name: "Amy", pounds_weight: 152, inches_height: 63}, {name: "Joe", pounds_weight: 120, inches_height: 64}, {name: "Tom", pounds_weight: 210, inches_height: 78}, {name: "Jim", pounds_weight: 180, inches_height: 68}, {name: "Jen", pounds_weight: 120, inches_height: 62}, {name: "Ann", pounds_weight: 252, inches_height: 63}, {name: "Ben", pounds_weight: 240, inches_height: 72}, ]; //functions to convert pounds to kg and inches to meters let...
WE ARE USING PYTHON TO COMPLETE THIS ASSIGNMENT :) THANK YOU! In this programming assignment, you...
WE ARE USING PYTHON TO COMPLETE THIS ASSIGNMENT :) THANK YOU! In this programming assignment, you will write functions to encrypt and decrypt messages using simple substitution ciphers. Your solution MUST include: a function called encode that takes two parameters: key, a 26-character long string that identifies the ciphertext mapping for each letter of the alphabet, in order; plaintext, a string of unspecified length that represents the message to be encoded. encode will return a string representing the ciphertext. a...
Parentheses Checking by python use a suitable class to write a function, given that the input...
Parentheses Checking by python use a suitable class to write a function, given that the input is the string of parentheses, check if they have the matching open and close brackets
Python programming 1. Use 0 and 1 only to complete the function that outputs how many...
Python programming 1. Use 0 and 1 only to complete the function that outputs how many N-long sequence are in total. Condition 1) Starts with zero and ends with zero 2) Zero does not exist twice in a row. 3) 1 does not exist three times in a row. 4) N is a natural number. - A sequence that satisfies the conditions. ex) 010, 0110, 01010 - A sequence that does not meet the conditions. ex) 0100, 01110, 01100110 Need...
Python programming 1. Use 0 and 1 only to complete the function that outputs how many...
Python programming 1. Use 0 and 1 only to complete the function that outputs how many N-long sequence are in total. Condition 1) Starts with zero and ends with zero 2) Zero does not exist twice in a row. 3) 1 does not exist three times in a row. 4) N is a natural number. - A sequence that satisfies the conditions. ex) 010, 0110, 01010 - A sequence that does not meet the conditions. ex) 0100, 01110, 01100110 Need...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT