Posts: 86
Threads: 13
Joined: Mar 2011
Reputation:
1
hey didnt exactly know were to put this but im learning my first programming language python and im having trouble understanding the basics if anyone has any tips about learning python that would be great also what your first programming language was and how you learned it it would be a big help thanks
Posts: 3,598
Threads: 265
Joined: Oct 2010
Reputation:
76
Python works a lot different from other languages because for example you don't work with {'s and }'s so much and the scope is determined by how much space you let in front of a line.
I can advise http://www.learnpython.org/ and http://diveintopython.org/
Posts: 86
Threads: 13
Joined: Mar 2011
Reputation:
1
05-24-2011, 21:54
(This post was last modified: 05-24-2011, 21:55 by ipwnedyou.)
went through most of learn python basic tutorials sort of got the hang of it but having a problem on an exercise
Print out all even numbers from the numbers list in the same order they are received, but only up to the number "412" (not including it).
the number list is [951, 402, 984, 651, 360, 69, 408, 319, 601, 485, 980, 507, 725, 547, 544,
615, 83, 165, 141, 501, 263, 617, 865, 575, 219, 390, 984, 592, 236, 105, 942, 941,
386, 462, 47, 418, 907, 344, 236, 375, 823, 566, 597, 978, 328, 615, 953, 345,
399, 162, 758, 219, 918, 237, 412, 566, 826, 248, 866, 950, 626, 949, 687, 217,
815, 67, 104, 58, 512, 24, 892, 894, 767, 553, 81, 379, 843, 831, 445, 742, 717,
958, 609, 842, 451, 688, 753, 854, 685, 93, 857, 440, 380, 126, 721, 328, 753, 470,
743, 527
]
if someone could explain how to do this and give code big thanks
Posts: 4
Threads: 0
Joined: Mar 2011
Reputation:
1
PYTHON Code
#Define the list. list = [951, 402, 984, 651, 360, 69, 408, 319, 601, 485, 980, 507, 725, 547, 544, 615, 83, 165, 141, 501, 263, 617, 865, 575, 219, 390, 984, 592, 236, 105, 942, 941, 386, 462, 47, 418, 907, 344, 236, 375, 823, 566, 597, 978, 328, 615, 953, 345, 399, 162, 758, 219, 918, 237, 412, 566, 826, 248, 866, 950, 626, 949, 687, 217, 815, 67, 104, 58, 512, 24, 892, 894, 767, 553, 81, 379, 843, 831, 445, 742, 717, 958, 609, 842, 451, 688, 753, 854, 685, 93, 857, 440, 380, 126, 721, 328, 753, 470, 743, 527] #Define a list for all the even numbers. newlist = [] #Start a loop. for i in list: #Break if we reach 412. #If we put this after the "even check" 412 would get included. if i == 412: break #If the number is even... if i%2==0: #Then append the list. newlist.append(i) #Print the list of even numbers print newlist
I'm guessing you have already solved this but I was bored
|