A cool python script to get teen learning python excited about programming? [closed]
So I'm teaching a friends son some python programming, just going through control of flow, basic data types/structures.
I want to go through a tutorial with him, and hopefully build something simple yet cool to get him excited about the power of python.
Any ideas?
Have a look at Invent Your Own Computer Games with Python from Albert Sweigart.
It has been written for beginners. It is available in the website of the link, but you can also buy the book if you prefer.
There is a blog with extra material with nice games as the classic gorillas or tetris.
Teach him map, reduce , lambda and other simple stuff :)
And then show him this code to find factorial of a series of number in one line.
(lambda k: reduce(int.__mul__, range(1,k+1),1))(8)
He will surely get excited
If he's into math, http://projecteuler.net/ might be worth checking out with him.
What is Project Euler?
Project Euler is a series of challenging mathematical/computer programming problems that will require more than just mathematical insights to solve. Although mathematics will help you arrive at elegant and efficient methods, the use of a computer and programming skills will be required to solve most problems.
Something simple I know some kids who had fun messing with this it's very helpful as merely looking as it will help the kid learn quite a bit.
age = input("How old are you?: ")
if age > 60:
print "If you're", age, "years old then why the **** are you clicking my python script?"
if age < 60 and age > 18:
print "Good for you..."
if age < 18:
print "You're", age, "shouldn't you be doing homework or something?"
import os
os.system("pause")
yeah,
ths might work.. im currently just for fun reading some stuff on encryption, i don't know what he is into exactly, but what he might like is to use python to be able to encrypt message's and do some string manipulations.
something simple to demonstrate what i mean:
plaintext = list('ABCDEFGHIJKLMNOPQRSTUVWXYZ')
encrytedtext = list('DEFGHIJKLMNOPQRSTUVWXYZABC')
def message(text, plain, encryp):
dictionary = dict(zip(plain, encryp))
newmessage = ''
for char in text:
try:
newmessage += dictionary[char]
except:
newmessage += ' '
print text, '\nhas been encrypted to:'
print newmessage
message('SEND THE MATERIAL NOW')
outputs: LTFR ZIT DQZTKOQS FGV
not md5 strength etc, but just basic letter replacement scheme's
now also get random sequences and then try to crack them
for example:
“EKNHZGUKQHIN OL ZIT LEOTFET ZIQZ EKTQZTL ZIT EOHITK LNLZTDL XLTR ZG IORT DTLLQUTL YKGD XFOFZTFRTR KTEOHOTFZL”.
Notice first that the most frequent cipher letter is T, probably replacing the E.
The 3-character stretch ZIT which appears twice could very well be THE and since Z
stands for T in that case, the word ZIQZ might be THAT. The 6th word now reads **EATE*
whose completion CREATES appears as a good choice. At this point, these successive guesses yield
the following partial decryption scheme,
Alphabet: ACEHRST
Substitution: QETIKLZ
You could try using the built-in turtle module to create some fractals, such as the Koch snowflake.
A game is clearly a nice thing. Maybe Tetris or Snake-like?
While commandline stuff are great to learn as you don't have to worry about graphical stuff they might be boring for a kid.
精彩评论