For one and all computer said I passed but, I know it's wrong


this is my code

my_list = [1,9,3,8,5,7]
for number in my_list:
my_list = number * 2
print my_list

Replace this line with your code.


What makes you say it's wrong, what should it do differently?
What are you asking for, you're not giving us anything to respond to!


The lesson said: Write a statement in the indented part of the for loop that prints a number equal to 2 * number for every list item.


Still no idea what you're looking for with this thread. You're not asking anything. You're stating facts.


What the code is supposed to do is multiply every number in the list by 2 and print the new list


You're still not asking anything.


my_list = [1,9,3,8,5,7]
for number in my_list:
my_list = number * 2
print my_list

it should print out [2,18,6,16,10,14]

it only prints out 14, and the computer says that I completed and passed


If I've learned anything on here in the last few weeks it's that this stuff requires perfect clarity and a lot of discipline and patience. You need to apply the same when asking for help. @ionatan evidently put in a decent effort pulling teeth to understand your issue, but if you're not clear or put little effort into asking for help, there's little chance of others wanting to help you. The post template provides formatting and posting rules, which makes it much easier for others to understand your problem; the onus is on you to be clear and concise.

I assume you're on 8. For One and All, and your code actually looks like this:

my_list = [1,9,3,8,5,7]
for number in my_list:
    my_list = number * 2
print my_list

At each turn in the loop, you're overwriting your existing variable my_list with only your most recent calculation. it basically understands it like this:

x = "Rainbow"
x = [1,2,3]
x = "Puppy"
print x #prints Puppy

To get the answer you're after, you need to print out the calculation without actually changing the original variable:

x = 1
print x + 1

Alternatively - if you actually want to save your new calculations - create a second variable for your new numbers:

x = 1
y = x + 1
print y


This is such a good response. Extremely refreshing to see such good wording and explanation, as well as implying the need for clarity in questions. You are correct in the answer too.
@padewan What you want to make sure of is indentation. If you're going to do it this way, to get the result you desire, just indent

print my_list

once so that it's inside the for each loop, and it will print every time. Additionally, you can just do
print my_list * 2 instead of

those two lines. :slight_smile:


Thanks, I like being helpful and I especially like being right :grin:
Now I'm gonna get cocky and correct you at the risk of making a fool out of myself...

Wouldn't that print [1,9,3,8,5,7,1,9,3,8,5,7]?
Without major spoiler, my answer had print number * 2


Wow, we're basically the same person!!

You are correct!! Thank you for pointing this out. Instead of those two lines you could use print number * 2

You are wrong here though, it actually prints

[1, 9, 3, 8, 5, 7, 1, 9, 3, 8, 5, 7]
[1, 9, 3, 8, 5, 7, 1, 9, 3, 8, 5, 7]
[1, 9, 3, 8, 5, 7, 1, 9, 3, 8, 5, 7]
[1, 9, 3, 8, 5, 7, 1, 9, 3, 8, 5, 7]
[1, 9, 3, 8, 5, 7, 1, 9, 3, 8, 5, 7]
[1, 9, 3, 8, 5, 7, 1, 9, 3, 8, 5, 7]

(That was a joke, I'm not saying your wrong just trying to console myself.)

EDIT: Actually, I'm wrong, you just were saying that's what that line would do.


Hi, everyone.

Some interaction from an IDLE session, copied below, exemplifies the results of multiplying an entire str or list by an int. It is useful to be aware of how this works, because this technique can be useful for some purposes, but it might not be what you need to do for the current exercise.

>>> "Hello, there" * 3
'Hello, thereHello, thereHello, there'
>>> [1, 2, 3] * 3
[1, 2, 3, 1, 2, 3, 1, 2, 3]


All you Guys and Gals are awesome. I did figure it out. What it was supposed to print was
[2,18,6,16,10,14] Not the same list twice.
And yes my major problem was indentation. I just have to figure out how to take a picture of my code on the monitor and show it when I need help. Hope that everyone has a wonderful and Happy Thanksgiving,,,,,your fellow apprentice,,,Padwean..


I'm just stoked my observations make sense and I can correct an expert without it backfiring on me (on the basics) :sunglasses:

No print needed? They lied to us!! :stuck_out_tongue_winking_eye:

To post your code, just click the < / > button above the text box and paste your code in between the triple apostrophe things

Your text will
    then print like this

Happy Thanksgiving from a non-American. Be thankful you still have 2 months before the world ends :stuck_out_tongue:


Hi, @lickwid ,

You actually do need print statements in your Codecademy submissions, in order to display output. The examples above were copied directly from an interactive session with the Python IDLE interpreter on a local computer, in which the user can enter individual statements or expressions. The IDLE prompt is ...


Whenever the user enters an expression at that prompt, the IDLE interpreter responds by displaying the value of that expression. By contrast, in Python scripts, which are what you are submitting on Codecademy, you do need print statements to display the values of expressions.

The examples from IDLE were posted in order to demonstrate the results of multiplication of str and list objects. IDLE can execute Python scripts as well as offer interactive sessions.


I'm not an expert at all, but thank you for thinking so! :slight_smile:

@appylpye That's really interesting, I haven't seen anything with a IDLE interpreter. Thanks for explaining this some.


IDLE is a bare-bones IDE for Python, written in Python (there's a module (just like the math module) that can be run to start IDLE)

It's.. basically there to make up for lacking knowledge of how to edit plain text and running Python with a file argument

The interactive mode (REPL, read-eval-print-loop) is Python, it's what you get when you type python in the terminal


That's actually pretty cool. I looked it up just curious and I see that it's just a super simple Python IDE.

I use python in the terminal sometimes.. I am not very good at manipulating terminal, using the command line, but I do know about it, I just don't have much experience.


Thank you for taking the time to goo step by step.
it helped a lot


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.