New values are not registred in the list


#1


https://www.codecademy.com/en/courses/python-beginner-en-pwmb1/1/5?curriculum_id=4f89dab3d788890003000096


Hey guys,


I want to print directly the new list with the print my_list right after the for loop but it still print me the old list with the non doubled numbers.


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

for number in my_list:
	print 2*number

print my_list  #This line should print the new my_list with the new values
	       # [1,9,3,8,5,7] => [2,18,6,16,10,14]
	       # I want it to print the new list


#2

How is this going to end up in the list?


#3

You're right, that's just a print but how to print the list with doubled numbers ?


#4

First you need to create it. Either by modifying the original list in place, or by spawning a new list. Do not print inside the loop.


#5

Okay I got it. This is the next exercice: " More with 'for' ".
I did it and I got it.

Thanks for the reply :grinning:


#6

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