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

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
This is C++ Create a program that reads an HTML file and converts it to plain...
This is C++ Create a program that reads an HTML file and converts it to plain text. Console: HTML Converter Grocery List * Eggs * Milk * Butter Specifications: The HTML file named groceries.html contains these HTML tags: <h1>Grocery List</h1> <ul> <li>Eggs</li> <li>Milk</li> <li>Butter</li> </ul> When the program starts, it should read the contents of the file, remove the HTML tags, remove any spaces to the left of the tags, add asterisks (*) before the list items, and display the...
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...
[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.
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...
Python 3 Fix the code so the program reads the file and see if the bar...
Python 3 Fix the code so the program reads the file and see if the bar code was already inputted 3 times if so, it ishows a warning indicating that the item was already tested 3 times Code: import tkinter as tk from tkcalendar import DateEntry from openpyxl import load_workbook from tkinter import messagebox from datetime import datetime window = tk.Tk() window.title("daily logs") window.grid_columnconfigure(1,weight=1) window.grid_rowconfigure(1,weight=1) # labels tk.Label(window, text="Bar code").grid(row=0, sticky="W", pady=20, padx=20) tk.Label(window, text="Products failed").grid(row=1, sticky="W", pady=20, padx=20) tk.Label(window,...
Create a program that reads a file of 2D coordinates and calculates the bounding box and...
Create a program that reads a file of 2D coordinates and calculates the bounding box and center of the bounding box. The bounding box is defined as the minimum area that fully encompasses all the coordinates. The center of that bounding box is calculated by taking the mean of the bounding box coordinates: ( x1+x2 2 , y1+y2 2 ). • If the input file cannot be opened, warn the user by printing "CANNOT OPEN FILE." to stdout. • Print...
(PYTHON) Write a program that does the following: reads each line from a txt file and...
(PYTHON) Write a program that does the following: reads each line from a txt file and convert it to lowercase counts the number of instances of: the characters 'a', 'e','i','o' and 'u' in the file creates a new file of file type .vowel_profile print outs lines in the file indicating the frequencies of each of these vowels Example input/output files: paragraph_from_wikipedia.txt (sample input) link: https://cs.nyu.edu/courses/fall19/CSCI-UA.0002-007/paragraph_from_wikipedia.txt paragraph_from_wikipedia.vowel_profile (sample output) link: https://cs.nyu.edu/courses/fall19/CSCI-UA.0002-007/paragraph_from_wikipedia.vowel_profile Please help!
Create a Python program file and . Your program will draw random circles with filled and...
Create a Python program file and . Your program will draw random circles with filled and non-filled color (random colors) and rectangles, fill andnon-fill color (also random colors) on the canvas. At least 10 for each category
Python! Create a program that does the following: Reads a number from the user. Calls a...
Python! Create a program that does the following: Reads a number from the user. Calls a function that finds all the divisors of that number. Calls another function to see if the number 7 is a divisor of the original number. Keeps reading input from the user and calling the function above until the user enters the letter ‘q’. Create 2 functions findDivisors() and lucky7(). Use docstrings to explain what each function does. Use the help() function to output the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT