Skip to content

Commit 7333873

Browse files
part 6.1 some exercises uploaded
1 parent d7aa18e commit 7333873

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@
3434
4. [Tuple](https://github.com/antoniolopez7217/Python_Programming_MOOC_2023_Introduction/tree/main/part5/4.%20Tuple)
3535

3636
### [Part 6](https://github.com/antoniolopez7217/Python_Programming_MOOC_2023_Introduction/tree/main/part6)
37-
1. Reading files
37+
1. [Reading files](https://github.com/antoniolopez7217/Python_Programming_MOOC_2023_Introduction/tree/main/part6/1.%20Reading%20files)
3838
2. Writing files
3939
3. Handling errors
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# The file fruits.csv contains names of fruits, and their prices, in the format specified in this example:
2+
3+
# banana;6.50
4+
# apple;4.95
5+
# orange;8.0
6+
# ...etc...
7+
# Please write a function named read_fruits, which reads the file and returns a dictionary based on the contents.
8+
# In the dictionary, the name of the fruit should be the key, and the value should be its price. Prices should be of type float.
9+
10+
# NB: the function does not take any arguments.
11+
# The file you are working with is always named fruits.csv.
12+
13+
def read_fruits():
14+
fruits_dict = {}
15+
with open("fruits.csv") as new_file:
16+
for line in new_file:
17+
line = line.replace("\n","")
18+
parts = line.split(";")
19+
fruits_dict[parts[0]] = float(parts[1])
20+
return fruits_dict

0 commit comments

Comments
 (0)