Where am I wrong?

Screen Link:

My Code:

INITIAL CODE

2
opened_file = open(‘AppleStore.csv’)
3
from csv import reader
4
read_file = reader(opened_file)
5
apps_data = list(read_file)
6

7
for app in apps_data[1:]:
8
price = float(app[4])
9
# Complete code from here
10
if price == 0:
11
app.append(‘free’)
12
elif price >= 0 and < 20:
13
app.append(‘affordable’)
14
elif price >= 20 and < 50:
15
app.append(‘affordable’)
16
elif price >= 50:
17
app.append(‘very expensive’)
18
apps_data[0].append(‘price_label’)
19

20
print(apps_data[:6])
21

Output
File “”, line 12
elif price >= 0 and < 20:
^
SyntaxError: invalid syntax

Replace this line with your code

What I expected to happen:

What actually happened:

Replace this line with the output/error

Hello @dim.velev! Please use triple backticks ``` to highlight your code so that for example this line “opened_file = open(‘AppleStore.csv’)” becomes opened_file = open(‘AppleStore.csv’). It’s much easier to read.

Regarding your question: your code is invalid because you have to specify which variable you want to complare at both sides of the and operator. So the correct code is elif price >= 0 and price < 20:
However your code can be more efficient. Can you think of a way to improve it?

Hint: your price should be between 0 and 20.

Happy coding:)

1 Like

@dim.velev

Welcome to the DataQuest community!

Please check out these guidelines for asking good questions.