Im building a program in which you can enter the tasks you have to do per day. Now I'm trying to make the program print a list of all the tasks when you're done adding them. This is the code I have:
for x in range(0,len(tuesday)):
print(" -",x)
tuesday is an array that contains all the tasks for that day. However, this code doesn't work; it just prints some numbers. How can I make the for loop print all the tasks from the tuesday array?
-
How do you initialize the array?Code-Apprentice– Code-Apprentice2014年01月11日 20:29:03 +00:00Commented Jan 11, 2014 at 20:29
2 Answers 2
You can do it like this:
tuesday = ["feed the dog", "do the homework", "go to sleep"]
for x in tuesday:
print x
would print:
feed the dog
do the homework
go to sleep
3 Comments
for x in range(0, len(tuesday)): print tuesday[x]for i,x in enumerate(tuesday):.enumerate()for x in range(0,len(tuesday)):
print(" -",x)
This code is not printing "random" numbers per se. It is printing the indices of all the elements in the tuesday array.
If you want to print the elements themselves, you will have to use this code:
for x in range(0,len(tuesday)):
print(" -",tuesday[x])
or
for x in tuesday:
print (x)