Error messages when my answers are correct

I noticed that I get error messages even when my answers are right( my codes). please how do I fix this.

Hi @samchukwusql2020,

If your code matches the answer code, you might want to try and restore your code to it’s initial state.

You can do that by clicking the circular arrows next to the Submit Answer button at the bottom of the mission screen (see image below).

image

You will then be asked if you want to keep my code or restore initial code.
Click restore initial code and try your answer again.

If this does not work, please provide a link to the mission you are working on and the code you have written for the answer.

Hope that helps,
Bradon

Thanks a lot I will try that. it’s indeed very fustrating when it says that I’m wrong even when the answer says that I’m right.

https://app.dataquest.io/m/313/conditional-statements/9/the-else-clause

if price == 0:
app.append(‘free’)
else:
app.append(‘non-free’)

apps_data[0] = apps_data.append(‘free_or_not’)
print(apps_data[0:4])

i have this same issue a lot. this is the code i am working on. what is wrong here?

i figured it out lol

1 Like

It’s not always easy to compare your code with the solution code and spot differences – sometimes your code can have a minor mistake/difference that you just can’t observe.

Since you mentioned that you’re getting error messages, there’s a good possibility that there’s something wrong with your code. My advice is to copy-paste your code and ask the community for help whenever you have doubts.

yes its not. sometimes i’m convinced i did the right thing and i get an error message. like this code below:
opened_file = open(‘AppleStore.csv’)
from csv import reader
read_file = reader(opened_file)
apps_data = list(read_file)
price_above_9 =
price_9_below =
for row in apps_data[1:]:
rating = float(row[7])
genre = row[11]
price = float(row[4])
if price > 9:
price_above_9.append(rating)

    avg_rating = sum(price_above_9)/ len(price_above_9)
    n_apps_more_9 = len(price_above_9)
    print(n_apps_more_9)
    
    if price <= 9:
        price_9_below.append(rating)
        n_apps_less_9 = len(price_9_below)
        print(n_apps_less_9)

it keeps telling me that n_apps_less_9 isn’t defined in my code. what does this mean?

If it tells you n_apps_less_9 is not defined in your code, it means you’re not initiating the n_apps_less_9 variable before using it. This is not straightforward to debug unless you send us the link to the screen you’re having problems with and copy-paste all the code you used, along with the error’s traceback (the full red message describing the error).

this is the error message:
n_apps_less_9 ()

  • actual + expected

  • [undefined]

  • 7019

this is the link to the screen:
https://app.dataquest.io/m/313/conditional-statements/8/comparison-operators

and this is the code i used:
opened_file = open(‘AppleStore.csv’)
from csv import reader
read_file = reader(opened_file)
apps_data = list(read_file)
price_above_9 =
price_9_below =
for row in apps_data[1:]:
rating = float(row[7])
genre = row[11]
price = float(row[4])
if price > 9:
price_above_9.append(rating)

    avg_rating = sum(price_above_9)/ len(price_above_9)
    n_apps_more_9 = len(price_above_9)
    print(n_apps_more_9)
    
    if price <= 9:
        price_9_below.append(rating)
        n_apps_less_9 = len(price_9_below)
        print(n_apps_less_9)