Question

In: Computer Science

Create a Python program that: Reads the content of a file (Vehlist.txt) The file contains matching...

Create a Python program that:

Reads the content of a file (Vehlist.txt)
The file contains matching pairs of vehicle models and their respective makes
Separate out the individual make and model on each line of the file
Add the vehicle make to one list, and the vehicle model to another list; such that they are in the same relative position in each list
Prompt the user to enter a vehicle model
Search the list containing the vehicle models for a match
If a match is found, display the vehicle make by accessing the vehicle make list entry in the same relative position the match was found
If no match is found, display a message saying so to the user
Allow the user to enter name for the file
The program should:

Use variables with meaningful names
Display easily understood prompts when collecting user input
Have appropriate comments indicating what each part of the program is doing
Have a comment area at the beginning of the program identifying the author of the program and the class it was created for
Save the program as a Python module, and submit the program through this assignment

Solutions

Expert Solution

Program Code [Python]

# Two lists to store models and makes of vehicles

models = []
makes = []

# Prompting user for name of file

fileName = input('Enter name of file: ')

# Reading file

vehicles = open(fileName, 'r')

for vehicle in vehicles:

    # Separating model and make by space and storing  in model and make variables

    model, make = vehicle.split(' ')

    # Adding in respective lists

    models.append(model)
    makes.append(make)

# Now asking user for a vehicle model

vModel = input('Enter a vehicle model: ')

# Now searching for that model in models list and getting index

index = -1 # Indicates that there is no match

for i in range(0, len(models)):

    if models[i] == vModel: # If model is in models list, get its index
        index = i
        break

if index != -1:
    print('Vehicle make is', makes[index])
else:
    print('No match found')

Vehlist.txt

Accord Honda
Prius Toyota
Grande Toyota
Corolla Honda
City Honda
Civic Honda

Sample Output:-

----------------------------------------------------------------------
COMMENT DOWN FOR ANY QUERIES!!!
HIT A THUMBS UP IF YOU DO LIKE IT!!!


Related Solutions

Python program: Write a program that reads a text file named test_scores.txt to read the name...
Python program: Write a program that reads a text file named test_scores.txt to read the name of the student and his/her scores for 3 tests. The program should display class average for first test (average of scores of test 1) and average (average of 3 tests) for each student. Expected Output: ['John', '25', '26', '27'] ['Michael', '24', '28', '29'] ['Adelle', '23', '24', '20'] [['John', '25', '26', '27'], ['Michael', '24', '28', '29'], ['Adelle', '23', '24', '20']] Class average for test 1...
Write a program in c that reads the content from the file and stores each line...
Write a program in c that reads the content from the file and stores each line in an int array in heap(using dynamic memory allocation). For example, let the file has elements following (we do not know the size of files, it could be above 100,000 and contents of the file and make sure to convert file elements to int): 10067 26789 6789 3467
Design and write a python program that reads a file of text and stores each unique...
Design and write a python program that reads a file of text and stores each unique word in some node of binary search tree while maintaining a count of the number appearance of that word. The word is stored only one time; if it appears more than once, the count is increased. The program then prints out 1) the number of distinct words stored un the tree, Function name: nword 2) the longest word in the input, function name: longest...
[In Python] Write a program that takes a .txt file as input. This .txt file contains...
[In Python] Write a program that takes a .txt file as input. This .txt file contains 10,000 points (i.e 10,000 lines) with three co-ordinates (x,y,z) each. From this input, use relevant libraries and compute the convex hull. Now, using all the points of the newly constructed convex hull, find the 50 points that are furthest away from each other, hence giving us an evenly distributed set of points.
I am trying to create a program that reads from a csv file and finds the...
I am trying to create a program that reads from a csv file and finds the sum of total volume in liters of liquor sold from the csv file by county and print that list out by county in descending order. Currently my program runs and gives me the right answers but it is not in descending order. I tried this:     for county, volume in sorted(sums_by_volume.items(), key=lambda x: x[1], reverse=True):         index +=1         print("{}. {} {:.2f}".format(county, sums_by_volume[county]))      When I run...
Write a Python program that reads a file, input by the user, containing one word/token per...
Write a Python program that reads a file, input by the user, containing one word/token per line with an empty line between sentences. The program prints out the longest word found in the file along with its length.
This is a python file Reads information from a text file into a list of sublists....
This is a python file Reads information from a text file into a list of sublists. Be sure to ask the user to enter the file name and end the program if the file doesn’t exist. Text file format will be as shown, where each item is separated by a comma and a space: ID, firstName, lastName, birthDate, hireDate, salary Store the information into a list of sublists called empRoster. EmpRoster will be a list of sublists, where each sublist...
For this problem, you'll be writing a script that reads the content of a file, modifies...
For this problem, you'll be writing a script that reads the content of a file, modifies that content, and then writes the result to a new file. a. Define a function called modified() that takes a string and returns a "modified" version of the string. The type of modification is up to you (be creative!), but I have a couple requirements: You must make at least two different modifications, and at least one of those modifications must be some kind...
Create and submit a Python program (in a module) that contains a main function that prints...
Create and submit a Python program (in a module) that contains a main function that prints 17 lines of the following text containing your name: Welcome to third week of classes at College, <your name here>! can someone please show me how to do this step by step? I'm just confused and keep getting errors in idle.
C++ Write a program that prompts for a file name and then reads the file to...
C++ Write a program that prompts for a file name and then reads the file to check for balanced curly braces, {; parentheses, (); and square brackets, []. Use a stack to store the most recent unmatched left symbol. The program should ignore any character that is not a parenthesis, curly brace, or square bracket. Note that proper nesting is required. For instance, [a(b]c) is invalid. Display the line number the error occurred on. These are a few of the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT