-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprogram3.py
54 lines (37 loc) · 1.44 KB
/
program3.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/bash/python3
"""As part three of your homework, you are asked to write a program that will ask a user to
enter <filename> as an input argument. Secondly, your program should read the file and saves
each line of the file as an element in a list and returns it (Note, the retuned value should not
have “\n”). The input file might look like the following:
Mazda, 21, 6, 160, 110, 3.9, 2.62
Valiant, 18.1, 6, 225, 105, 2.1, 3, 46
Cadillac, 10.4, 8, 472, 205, 2.93, 5.25
Full version of the file can be downloaded here
(https://gist.github.com/ssheff/9817ab169a7aa6f9143ef7868b3ddda7)
Your program(function) should return a list as the following:
[‘Mazda, 21, 6, 160, 110, 3.9, 2.62’, ‘Valiant, 18.1, 6, 225, 105, 2.1, 3, 46’, ‘Cadillac,
10.4, 8, 472, 205, 2.93, 5.25’]
"""
import csv
import sys
def my_read_function(cars):
print(cars)
# Preparing a file
file_prompt = open(cars, mode='r')
# Redaing file using realines() function
car_data = file_prompt.readlines()
#print(car_data)
#sys.exit()
#creating empty list file
car_output_list =[]
#stripping "\" from each line"
for line in car_data:
#print(line)
line_with_no_new_line=line.strip()
car_output_list.append(line_with_no_new_line)
#print(car_output_list)
#sys.exit()
return car_output_list
if __name__ == "__main__":
print_out_car=my_read_function("cars.csv")
print(print_out_car)