Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Hello. I made a program that displays a list of customers and their info but does not show anything that does not fit in the
Hello. I made a program that displays a list of customers and their info but does not show anything that does not fit in the parameters laid out in the code. I have added more customers to my list and for some reason I'm getting the following error:
File "/home/ec2-user/environment/Week 4/Lab 4 Part 2.py", line 175, in <module> customers = list(map(display, customer_list)) File "/home/ec2-user/environment/Week 4/Lab 4 Part 2.py", line 171, in display return "{:>30}".format(check_first_name(first_name))+"{:>30}".format(check_last_name(last_name)) + "{:>30}".format(check_zip(Zip)) + "{:>30}".format(check_phone(ph)) TypeError: unsupported format string passed to NoneType.__format__
I originally had 8 different customers in my list and I changed it to 25. It was working with 8. I'm not sure what I need to change. My current code is below.
import pandas as pd from random import randint # lists of data first_names = [ "Tom", "Susan", "Zack", "Stephan", "Louis", "Billy", "Linda", "Raul", "Robert", "Paul", "Xavier", "Taylor", "Jonny", "Johnathan", "Patrick", "Moira", "Timothy", "Javier", "156331.1", "Tulip", "45", "Bryce", "Donna", "Randy", "Duane"] last_names = [ "Johnson", "Armstrong", "Jackson", "Arnold", "Davis", "Watson", "Garfield", "Stoneking", "Davidson", "Grande", "1365122", "1", "Surandon", "Johnathan", "Vaughan", "Brenner", "987", ".6", "Poppy.1", "Winn", "Nicholson", "Warner", "Brown", "Blue", "Johnson"] zip_code = [ "32654", "96536-1987", "456", "36965953", "96584", "963852", "xc", "95632", "36412365", "45986-4212", "13654785", "96458", "78459", "98745845458454", "33333", "x", "96864", "12365-4584", "99545", "98641", "964", "1.2", "98521", "32654", "12546"] phone = [ "965-698-4596", "8954621365", "85963545", "6985", "tys", "985-986-4685", "897-695-4512", "8975462136", "986-654-2136", "9658741532", "965-415-35215", "968-745-5432", "458.65.6954", "451.652.1253", "695-458-4512", "3264125041", "969-854-7845", "652-451-3625", "3201203252", "32362", "659410253", "985475130", "9658654121", "3261451201", "965-745-4851"] # prameters for customer list customer_list = [] for i in range(len(first_names)): customer_list.append({"First Name": first_names[i], "Last Name": last_names[i], "Zip Code": zip_code[i], "Phone": phone[i]}) # checking to see if first and name is string of letters def check_first_name(first_names): for first_name in first_names: if not first_name.isalpha(): first_name = "" else: return first_names def check_last_name(last_names): for last_name in last_names: if not last_name.isalpha(): last_name = "" else: return last_names # check to see if Zip is in right format and is int def check_zip(zip_code): while "-" in zip_code: zip_code = zip_code.replace("-", "") if not zip_code.isdigit(): return "" zip_code = int(zip_code) if zip_code < 9: return "" else: return zip_code # checks phone to see if in right format and is integer def check_phone(phone): while "-" in phone: phone = phone.replace("-", "") if len(phone) < 10: return "" elif not phone.isdecimal(): return "" else: return phone customer_list.append({"First Name": first_names[i], "Last Name": last_names[i], "Zip Code": zip_code[i], "Phone": phone[i]}) def display(customer): first_name = customer['First Name'] last_name = customer['Last Name'] Zip = customer['Zip Code'] ph = customer['Phone'] return "{:>30}".format(check_first_name(first_name))+"{:>30}".format(check_last_name(last_name)) + "{:>30}".format(check_zip(Zip)) + "{:>30}".format(check_phone(ph)) print("{:>30}{:>30}{:>30}{:>30}".format( "First name", "Last name", "Zip code", "Phone number")) customers = list(map(display, customer_list)) for customer in customers: print(customer)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started