Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
python
#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
Reply

#2
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/
Reply

#3
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
Reply

#4
PYTHON Code
  1. #Define the list.
  2. list = [951, 402, 984, 651, 360, 69, 408, 319, 601, 485, 980, 507, 725, 547,
  3. 544, 615, 83, 165, 141, 501, 263, 617, 865, 575, 219, 390, 984, 592,
  4. 236, 105, 942, 941, 386, 462, 47, 418, 907, 344, 236, 375, 823, 566,
  5. 597, 978, 328, 615, 953, 345, 399, 162, 758, 219, 918, 237, 412, 566,
  6. 826, 248, 866, 950, 626, 949, 687, 217, 815, 67, 104, 58, 512, 24,
  7. 892, 894, 767, 553, 81, 379, 843, 831, 445, 742, 717, 958, 609, 842,
  8. 451, 688, 753, 854, 685, 93, 857, 440, 380, 126, 721, 328, 753, 470,
  9. 743, 527]
  10. #Define a list for all the even numbers.
  11. newlist = []
  12.  
  13. #Start a loop.
  14. for i in list:
  15. #Break if we reach 412.
  16. #If we put this after the "even check" 412 would get included.
  17. if i == 412:
  18. break
  19. #If the number is even...
  20. if i%2==0:
  21. #Then append the list.
  22. newlist.append(i)
  23.  
  24. #Print the list of even numbers
  25. print newlist


I'm guessing you have already solved this but I was bored Tongue
Reply



Possibly Related Threads…
Thread Author Replies Views Last Post
  [Request] python only kashwak 3 1,936 03-27-2012, 11:25
Last Post: Rendflex
  [Release] shiny Pack a Punch zombie camo & silver Colt Python reylobo14 10 13,841 09-08-2011, 09:43
Last Post: Wolfshagger
  [Release] python mod george1589 6 3,633 08-04-2011, 13:08
Last Post: d0h!
  Triple Python Bloopbloop 6 2,993 11-17-2010, 01:11
Last Post: Bloopbloop

Forum Jump:


Users browsing this thread:
1 Guest(s)

Forum Powered By MyBB, Theme by © 2002-2024 Melroy van den Berg.