I need to adapt a version using pyInputPlus functions to perform…
Question Answered step-by-step I need to adapt a version using pyInputPlus functions to perform… I need to adapt a version using pyInputPlus functions to perform all the input validation and for the main() loop decision. • Program base should be adjust to allow book prices to include $ and cents. Restrict individual book prices to $100 maxium. Example with string limit:import pyinputplus as pyip # string input with additional parametersmyInput = pyip.inputStr(prompt = “Enter an string… “, default = “A”, limit =2)print(‘My default if left blank:’ , myInput) 5OTHER EXAMPLE:>>> import pyinputplus as pyip>>> result = pyip.inputStr()>>> result = pyip.inputNum(min=4, max=6)3Input must be at minimum 4.7Input must be at maximum 6.4>>> result4 PROGRAM BASE/REFERENCE: import randomglobal name_list, price_listname_list = []price_list = []def main(): print(‘This program summarizes a book list.’) num_books, price_list = first_inputs() total, average = processing(price_list) outputs(num_books, price_list, total, average, name_list) restart = input(‘Need more books? Enter y or n: ‘) if restart == ‘y’: print(‘OK, let’s try a new list.’) main() else: print(‘Thanks for using the program.’)# collect user’s informationdef first_inputs(): print(‘Enter the number of books that you need ‘) num_books = get_pos_int() for index in range(num_books): book_name = input_book_name(index) print(f’Enter the cost of {book_name}, to the nearest dollar: ‘) book_cost = get_pos_int() book_cost = round(book_cost, 2) price_list.append(book_cost) return num_books, price_list# validationdef get_pos_int(): pos_int = input(‘Please enter a whole number: ‘) while pos_int.isnumeric() is False or int(pos_int) == 0: pos_int = input(‘Enter a number greater than 0: ‘) pos_int = int(pos_int) return pos_int# collect user’s informationdef input_book_name(index): name = input(f’Enter the name of the book #{index + 1} ‘) if name.isdigit(): name = get_pos_str() name_list.append(name) return name# collect and validate an strdef get_pos_str(): pos_str = input(‘Please only names, no numbers: ‘) while pos_str.isalpha() is False: pos_str = input(‘Names please: ‘) pos_str = str(pos_str) return pos_str# define resultsdef processing(price_list): total = sum(price_list) average = total / len(price_list) average = format(average, ‘.2f’) total = format(total, ‘.2f’) return total, average# display the resultsdef outputs(num_books, price_list, total, average, name_list): print(f’Info on {num_books} Books Needed n’) print(“%-20s %-40s ” % (‘Books’, ‘Price’)) for name in range(len(name_list)): price = format(price_list[name], ‘.2f’) print(“%-20s $ %-40s” % (name_list[name], price)) print() print(f'{“Total”:<20s} $ {total:>5s}’) print(f'{“Average”:<20s} $ {average:>5s}’)main() Output: Image transcription textThis program summarizes a book list. Enter the number of book: that you need: Please enter a whole ntmber:three Enter a number greater than 0: 3 Enter the name of book #1: The Mneller Report Enter cost of TheMueller Report, to the nearest dollar: Please enter a whole number: 18 Enter the name of book #2:… Show more… Show more Here are the functions used to take various types of input :inputNum() : Accepts a numeric value. It takes additional parameters ‘min’, ‘max’, ‘greaterThan’ and ‘lessThan’ for bounds. Returns an int or float.inputStr() : Accepts a string value. It provides features such as ‘blockRegexes’, ‘timeout’, ‘limit’ etc.inputInt() : Accepts an integer value. This also takes additional parameters ‘min’, ‘max’, ‘greaterThan’ and ‘lessThan’ for bounds. Returns an int.inputFloat() : Accepts a floating-point numeric value. Also takes additional ‘min’, ‘max’, ‘greaterThan’ and ‘lessThan’ parameters. Returns a float.inputBool() : Accepts a boolean value. Input can be any case-insensitive form of ‘true’/’false’ and ‘T’/’F’. Returns a boolean value.inputChoice() : Takes a list of strings and accepts one of them as input.inputMenu() : Similar to inputChoice(), but the choices are presented as items in a menu. Menu items can be marked with letters or numbers, using the ‘lettered’ and ‘numbered’ parameters.inputDate() : Accepts a date in a strftime format. We need to pass this format to the ‘formats’ parameter. Returns a datetime.date object.inputTime() : Accepts a time in a strftime format. Returns a datetime.time object.inputDatetime() : Accepts a date and time in a strftime format. Returns a datetime.datetime object.inputYesNo() : Accepts ‘yes’/’no’ or ‘y’/’n’ in case-insensitive form. Returns ‘yes’ or ‘no’. Computer Science Engineering & Technology Python Programming COMPUTER S 120 Share QuestionEmailCopy link Comments (0)


