Exam: Data Science Foundations

Hello,

I have been experiencing frustration with the precision and specific examples required to get credit in the Data Science Foundations Exam.

I have just submitted question 2 (asking to order by Grade) but for whatever reason despite pulling that exact data, i was not given credit. I am now 2 “check answers” down on question 4:
with my answer as follow:

All of our store items

all_items = [[“Taffy”, 1], [“Chocolate”, 2], [“Cup”, 5], [“Plate”, 10], [“Bowl”, 11], [“Silverware”, 22]]

Empty discounted_items list

discounted_items =

Your code here

for x,y in all_items:
if y%2 == 1:
discounted_items.append(x)

For testing purposes: print discounted list

print(discounted_items)

the check is telling me I haven’t run the loop? What am I missing?? This is incredibly frustrating I’ve done this exam 3 times now, and have been able to pull the exact data for every entry- but routinely get credit for only 4/6, marking as an incomplete grade.

1 Like

I’m not familiar with said exam. Do you have a link?

Your (formatted) code prints on my end.

>>['Taffy', 'Cup', 'Bowl']

Not sure why the error. Maybe copy your work, clear the code and refresh the page(?)

I have the same problem. The refresh doesn’t help at all.
Here is the link:
https://www.codecademy.com/exams/journeys/data-scientist-aly/paths/dsalycj-22-data-science-foundations/parts/2

I can’t view the exam, but I am just wondering whether the instructions give any examples.
Is the result supposed to be a list of strings or is it supposed to be a list of lists i.e.
Is discounted_items supposed to be:

['Taffy', 'Cup', 'Bowl']

or is it supposed to be:

[['Taffy', 1], ['Cup', 5], ['Bowl', 11]]

? Do the instructions include an example of sample output?

Hi,
Sorry for my bad english, I’m french.
I’ve the same frustation.
I think that before run the odd list, we have to run a “simple loop” .
Tomorow I’ll test this :

all_items = [[“Taffy”, 1], [“Chocolate”, 2], [“Cup”, 5], [“Plate”, 10], [“Bowl”, 11], [“Silverware”, 22]]

discounted_items =

for item in all_items:
print(item)

for variable1, variable2 in all_items:
if variable2 % 2 != 0:
discounted_items.append(variable1)

print(discounted_items)

Tell me if you find a solution :slight_smile:

I’ve difficult time with all the exams , I had to study again the Data Science Foundations I part to complete exam 1. But it was really hard to me …

Zenaba

Hi,
Did you find any solution ? I’m stuck too it’s very frustrating I don’t understand why they keep telling me that I haven’t run the loop … I’m missing something idk what

thanks for your help
Zenaba

did you finally find the solution? i am having the exact problem!

Well I got it to work. You have to use a for i in range(len(some_list)): loop rather than a for x, y in some_list: loop. Then access the elements of the lists by their index. WAY to picky in my opinion.

1 Like

too picky but it works! thanks for your help :slight_smile:

1 Like

Hello! How did you access the elements of the lists by their index?
I’m stuck at this problem. Thanks!

Hi! Me too! :smiling_face_with_tear:
help please!

Finally!

for i in range(len(all_items)):
if i % 2 == 0:
discounted_items.append(all_items[i])
print(discounted_items)

hello there, been stuck on this question for a while now. Tried your code, works for the most part but now it’s asking if I’ve included print(dicsounted_items) at the end of my code.
Here’s how I typed it did I type it incorrectly somehow?
Capture

It should be:

all_items = [[“Taffy”, 1], [“Chocolate”, 2], [“Cup”, 5], [“Plate”, 10], [“Bowl”, 11], [“Silverware”, 22]]

discounted_items =

for x, y in all_items:
if y % 2 == 1:
discounted_items.append(x)

print(discounted_items)

This is essentially what I did but it’s telling me to make sure to print the discounted items list at the end of my code. Not sure where this is going wrong but it prints out correctly.

# All of our store items all_items = [["Taffy", 1], ["Chocolate", 2], ["Cup", 5], ["Plate", 10], ["Bowl", 11], ["Silverware", 22]] # Empty discounted_items list discounted_items = [] # Your code here for item in all_items: if item[1] % 2 != 0: discounted_items.append(item) print(discounted_items) # For testing purposes: print discounted list # print(discounted_items)
1 Like

I guess I see what it’s ideally asking for. The item itself, not the price with it?

for item in all_items:

if item[1] % 2 != 0:

  discounted_items.append(item[0])
1 Like

First of all, I noticed that your code has some syntax errors that might prevent it from running correctly. For example, you are using curly quotes (“ ”) instead of straight quotes (" ") for your strings and list elements. You also need to indent your code properly to show the structure of your loop and conditional statement. Here is how your code should look like:

# All of our store items
all_items = [["Taffy", 1], ["Chocolate", 2], ["Cup", 5], ["Plate", 10], ["Bowl", 11], ["Silverware", 22]]

# Empty discounted_items list
discounted_items = []

# Your code here
for x,y in all_items:
    if y%2 == 1:
        discounted_items.append(x)

# For testing purposes: print discounted list
print(discounted_items)

no they do not give sample print outs at the exam levels, even though they sometimes do at the exercise level, and it helps a great deal.
So, the problem with the exam is that they only give you 3 times to check the answer, it is very frustrating.
My code is:

All of our store items

all_items = [[“Taffy”, 1], [“Chocolate”, 2], [“Cup”, 5], [“Plate”, 10], [“Bowl”, 11], [“Silverware”, 22]]

Empty discounted_items list

discounted_items =

Your code here

for item in all_items:
if item[1]%2 != 0:
discounted_items.append(item)
print(discounted_items)

wich prints this:
[[‘Taffy’, 1], [‘Cup’, 5], [‘Bowl’, 11]]

and I can replace this line:
discounted_items.append(item)

for:
discounted_items.append(item[0])
which will give me this:
[‘Taffy’, ‘Cup’, ‘Bowl’]

BUT, I have only ONE more “check answer” left, and I am affraid to waste it.
CODECADEMY could be a bit more specific about these things!

BINGO! SOLVED!
Got the clapping hands!
This is the code I used:

All of our store items

all_items = [[“Taffy”, 1], [“Chocolate”, 2], [“Cup”, 5], [“Plate”, 10], [“Bowl”, 11], [“Silverware”, 22]]

Empty discounted_items list

discounted_items =

Your code here

for item in all_items:
(indent) if item[1]%2 != 0:
(indent) (indent) discounted_items.append(item[0])

For testing purposes: print discounted list

print(discounted_items)

Which printed this: [‘Taffy’, ‘Cup’, ‘Bowl’]