Menu

[Solved]Task 1 Write Python Program Takes Input User Name File Containing Postcode Location Inform Q37020174

python code:

Task 1: Write a Python program that takes as input from the user the name of a file containing postcode/location information.Improving Readability Modify your program in Task 1 so that it prints the list in a more readable format. For example: your p

Task 1: Write a Python program that takes as input from the user the name of a file containing postcode/location information. Each line in the file consists of the postcode followed by a tab followed by a comma-separated list of locations that have that postcode. For example, the file Small.txt contains: 3015 Newport,South Kingsville,Spotswood 3016 Williamstown 3018 Altona,Seaholme 3019 3021 Albanvale,Kealba,Kings Park,St Albans Braybrook, Robinson Your program should create a list of postcode/location pairs with each pair stored in the list. It should print the list, so that you can check that your program has performed correctly For example: your program may do the following: Enter name of postcode file: Small.txt [[3015, ‘Newport’], [3015, ‘South Kingsville’], [3015, ‘Spotswood’], [3016, ‘Williamstown’1, [3018, ‘Altona’], [3018, ‘Seaholme’], [3019, ‘Braybrook’l, [3019, ‘Robinson’, [3021, ‘Albanvale’], [3021, ‘Kealba’], [3021, ‘Kings Park’], [3021, ‘St Albans’11 Note You will need to use split twice: first to separate the postcode from the rest of the string and secondly to separate the rest of the strings into individual locations. Improving Readability Modify your program in Task 1 so that it prints the list in a more readable format. For example: your program may do the following: Enter name of postcode file: Small.txt 3015 Newport 3015 South Kingsville 3015 Spotswood 3016 Williamstown 3018 Altona 3018 Seaholme 3019 Braybrook 3019 Robinson 3021 Albanvale 3021 Kealba 3021 Kings Park 3021 St Albans Task 2 Write a function BinarySearch1 takes as input a list L and a string and uses a recursive binary search to find an entry in the list with a suburb that matches the given string. Your function should return the index in L if the string is found or -1 if it is not found. You may find it useful to look at the Python code for iterative Binary Search given in: Divide and conquer (Lecture 13) Modify your program in Task 2 so that it asks the user for the name of a suburb and uses BinarySearch1 to find the postcode of the given suburb. If the suburb is not in the database, your program should print “Not Found, otherwise it should print the postcode Note: Since the suburb names are not sorted, you will first be required to sort the list according to the suburb names. To do this, you may use the selection sort code you developed in Week 5 Task 3. If you struggled with week 5 task 3, you may ask your tutor for assistance. For Example: Your program may output: Enter name of postcode file: SMALL.txt Enter Suburb Name: Newport Post code is 3015 Show transcribed image text Task 1: Write a Python program that takes as input from the user the name of a file containing postcode/location information. Each line in the file consists of the postcode followed by a tab followed by a comma-separated list of locations that have that postcode. For example, the file Small.txt contains: 3015 Newport,South Kingsville,Spotswood 3016 Williamstown 3018 Altona,Seaholme 3019 3021 Albanvale,Kealba,Kings Park,St Albans Braybrook, Robinson Your program should create a list of postcode/location pairs with each pair stored in the list. It should print the list, so that you can check that your program has performed correctly For example: your program may do the following: Enter name of postcode file: Small.txt [[3015, ‘Newport’], [3015, ‘South Kingsville’], [3015, ‘Spotswood’], [3016, ‘Williamstown’1, [3018, ‘Altona’], [3018, ‘Seaholme’], [3019, ‘Braybrook’l, [3019, ‘Robinson’, [3021, ‘Albanvale’], [3021, ‘Kealba’], [3021, ‘Kings Park’], [3021, ‘St Albans’11 Note You will need to use split twice: first to separate the postcode from the rest of the string and secondly to separate the rest of the strings into individual locations.
Improving Readability Modify your program in Task 1 so that it prints the list in a more readable format. For example: your program may do the following: Enter name of postcode file: Small.txt 3015 Newport 3015 South Kingsville 3015 Spotswood 3016 Williamstown 3018 Altona 3018 Seaholme 3019 Braybrook 3019 Robinson 3021 Albanvale 3021 Kealba 3021 Kings Park 3021 St Albans Task 2 Write a function BinarySearch1 takes as input a list L and a string and uses a recursive binary search to find an entry in the list with a suburb that matches the given string. Your function should return the index in L if the string is found or -1 if it is not found. You may find it useful to look at the Python code for iterative Binary Search given in: Divide and conquer (Lecture 13) Modify your program in Task 2 so that it asks the user for the name of a suburb and uses BinarySearch1 to find the postcode of the given suburb. If the suburb is not in the database, your program should print “Not Found, otherwise it should print the postcode Note: Since the suburb names are not sorted, you will first be required to sort the list according to the suburb names. To do this, you may use the selection sort code you developed in Week 5 Task 3. If you struggled with week 5 task 3, you may ask your tutor for assistance. For Example: Your program may output: Enter name of postcode file: SMALL.txt Enter Suburb Name: Newport Post code is 3015

Expert Answer


Answer to Task 1: Write a Python program that takes as input from the user the name of a file containing postcode/location informa… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *