Monday, December 14, 2015

#Tuesday #Coding #PythonDay --- "Explicit is better than implicit "


Fun coding day again! Back to my journey of CodeCombat game! Winston Churchill once said “we are the beginner of the beginner”, so let me start from the very beginning --- the first 2 or 3 levels are very simple (also quite similar), we just need to type in movement commands, and our hero will grab all the gems and avoid the spikes, etc. We can skip them and jump to “Forgetful Gemsmith”. 

Our goals for the level of “Forgetful Gemsmith”:
  • Hero must survive.
  • Collect all 4 gems.
  • Get to the exit.
  • Bonus: no code problems.
  • Bonus: under 9 statements.
Coding is as following:

self.moveRight()
self.moveUp()
self.moveRight(2)
self.moveDown(2)
self.moveUp()
self.moveRight()

With the argument (that value in the brackets) assigned to the function, we don’t need to write self.moveRight() twice. Python is all for its beauty of explicit, that’s why we have ‘self’ here. Also don’t forget EVERYTHING in Python is an object, including modules.






Again, maybe you’d like to read “Zen of Python” https://en.wikipedia.org/wiki/Zen_of_Python  or to know more about the genius behind this beauty Python ---  Guido van Rossum  https://en.wikipedia.org/wiki/Python_(programming_language) 

Finally, read the attached fun facts based on the in-game survey I took:

Question 1: What is your favorite programming language? 

48% of people chose Python!



Question 2: Your gender?

77% of players are male, 15% female, and there is 8% ''other".




Happy coding & Have a nice week ahead!

No comments:

Post a Comment