Below is my code and an image of the prompt. The code runs but according to my professor I cant use built in functions such as in Line 4[clientList.append(fullName)], Line 17[clientList.insert(index, fullName)], & Line 46[combined_data.sort(reverse=True)]. I also cannot use these other functions such as Sort,Max,Min,Append,Insert & Remove.
Below is my code and an image of the prompt. The code runs but according to my professor I cant use built in functions such as in Line 4[clientList.append(fullName)], Line 17[clientList.insert(index, fullName)], & Line 46[combined_data.sort(reverse=True)]. I also cannot use these other functions such as Sort,Max,Min,Append,Insert & Remove.
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
Below is my code and an image of the prompt.
The code runs but according to my professor I cant use built in functions such as in
Line 4[clientList.append(fullName)],
Line 17[clientList.insert(index, fullName)],
& Line 46[combined_data.sort(reverse=True)].
I also cannot use these other functions such as Sort,Max,Min,Append,Insert & Remove.
Im suppose to replace the built in function and create my own functions but im not sure how and hopefully someone can solve it for me.
My Code(Python)
import sys
def addClient(clientList, balanceList, fullName, balance):
clientList.append(fullName)
balanceList.append(balance)
def removeClient(clientList, balanceList, fullName):
if fullName in clientList:
index = clientList.index(fullName)
clientList.pop(index)
balanceList.pop(index)
else:
print("Client not found.")
def insertClient(clientList, balanceList, fullName, index, balance):
if index >= 0 and index <= len(clientList):
clientList.insert(index, fullName)
balanceList.insert(index, balance)
else:
print("Invalid index. Index should be between 0 and", len(clientList))
def deposit(balanceList, index, depositAmount):
if index >= 0 and index < len(balanceList):
balanceList[index] += depositAmount
else:
print("Invalid index. Index should be between 0 and", len(balanceList) - 1)
def withdraw(balanceList, index, withdrawAmount):
if index >= 0 and index < len(balanceList):
if balanceList[index] >= withdrawAmount:
balanceList[index] -= withdrawAmount
else:
print("Insufficient balance.")
else:
print("Invalid index. Index should be between 0 and", len(balanceList) - 1)
def searchFirstName(clientList, firstName):
matching_indices = [i for i, name in enumerate(clientList) if firstName in name]
if matching_indices:
return matching_indices
else:
return None
def sortingDescending(clientList, balanceList):
combined_data = list(zip(clientList, balanceList))
combined_data.sort(reverse=True)
clientList, balanceList = zip(*combined_data)
def displayList(clientList, balanceList):
for i in range(len(clientList)):
print(f"{clientList[i]} - Balance: ${balanceList[i]:.2f}")
def exit_program():
print("Exiting the program.")
sys.exit()
clientList = ["Mike Navarro", "Miguel Saba", "Maria Rami"]
balanceList = [900.00, 400.00, 450.00]
while True:
print("\nMenu:")
print("1- Add a new client")
print("2- Remove a client")
print("3- Insert an item to the list")
print("4- Deposit")
print("5- Withdraw")
print("6- Search for a client based on firstName")
print("7- Sort the list in descending order")
print("8- Display the list")
print("9- Quit the program")
choice = input("Enter your choice: ")
if choice == '1':
fullName = input("Enter full name: ")
balance = float(input("Enter initial balance: "))
addClient(clientList, balanceList, fullName, balance)
elif choice == '2':
fullName = input("Enter the full name of the client to remove: ")
removeClient(clientList, balanceList, fullName)
elif choice == '3':
fullName = input("Enter full name: ")
index = int(input("Enter index: "))
balance = float(input("Enter balance: "))
insertClient(clientList, balanceList, fullName, index, balance)
elif choice == '4':
index = int(input("Enter index: "))
depositAmount = float(input("Enter deposit amount: "))
deposit(balanceList, index, depositAmount)
elif choice == '5':
index = int(input("Enter index: "))
withdrawAmount = float(input("Enter withdrawal amount: "))
withdraw(balanceList, index, withdrawAmount)
elif choice == '6':
firstName = input("Enter first name to search: ")
matching_indices = searchFirstName(clientList, firstName)
if matching_indices:
for index in matching_indices:
print(f"Found at index {index}: {clientList[index]} - Balance: ${balanceList[index]:.2f}")
else:
print("Client not found.")
elif choice == '7':
sortingDescending(clientList, balanceList)
elif choice == '8':
displayList(clientList, balanceList)
elif choice == '9':
exit_program()
else:
print("Invalid choice. Please select a valid option.")
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 3 images
Recommended textbooks for you
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education