These days to learn a bit of Python before you want to take Nodejs to the back end of the study, because it is written with JS to write, but after a period of time to find out in fact Nodejs learning is still a lot of things to learn, many things need to write their own, but as a rookie, it is difficult, In addition to this reason also because of Python's concise grammar or seduced me, so learned a few days, talk about these days to learn things.
Indented in Python instead of {}
If 1>0:
Print (' right ');
Else
Print (' wrong ');
Python inside the array of some syntax sugar is still very fond of, I hope JS will have such a good.
list = [' A ', ' B ', ' C '];
# get the last one
Print (list[-1]); #c
# intercept the value between index 0-2 does not include 2
Print (List[0:2]); #[' A ', ' B ']
# Intercept index 1 to the end of the value
Print (list[1:]); #[' B ', ' C ']
Although JS can get the last value through arr.length-1, it still likes the Python notation.
In fact, the basic content of these languages are similar, but the name of a change, the wording changed a bit.
Two small games were written in Python.
#Shoot the ball small game#coding=gb2312 fromRandomImportChoicedir= [' Left','Center',' Right'];defKick (NUM): Score=[0,0]; forIinchrange (num): Randir=Choice (dir); Userdir= Raw_input ('Please enter the direction you want to shoot the ball:'); ifuserdir!=Randir:score[0]+=1; Print('congratulations on shooting the ball. Score plus 1'); Else: score[1]+=1; Print('you shot the ball by the goalkeeper bar, re-enter a direction. '); Print('your score is:%d, the total opponent score is:%d'% (score[0],score[1])); returnScore;result= Kick (4); whileResult[0]==result[1]: Print('you two have a tie, one more time. '); Result= Kick (4);ifResult[0]>result[1]: Print('congratulations on defeating your opponent! ');Else: Print('It's a pity that the opponent defeated you. ');
#coding=gb2312#猜数字小游戏
#Import Module fromRandomImportRandint;Print('------Start the game---------');#Random numberran = Randint (0,100); Content= Input ('Please enter the number you want to guess:');#Record inresult =[0,0,0];result[0]= 1;#Wrong Guess whileran!=Content:resu='and target value 108,000 miles apart! '; ifABS (Content-ran) <=5: ResU='you guessed the result and the goal is very close to Oh! '; elifABS (Content-ran) <20: ResU='The difference is a little distance! '; Print('The number you guessed is%d,%s\n.'%(Content,resu)); result[2]+=1; result[1]+=1; Content= Input ('Please re-enter a number:');#Times plus 1Result[2]+=1; result[1]+=1;Print('-------, Congratulations, you guessed it-------\ n');#try to read the fileTry: F= Open ('Data.txt'); Data=F.read (). split (); F.close ();except: #If you do not have this file, create aout = open ('Data.txt','W'); Out.write ('0 0 0'); Out.close (); F= Open ('Data.txt'); Data=F.read (). split (); F.close (); Game_times= Int (data[0]) +Result[0];min_times= Int (data[1]); Total_times= Int (data[2]) + result[2];#Write a fileout = open ('Data.txt','W');ifResult[1]<min_timesorInt (data[0]) = =0:min_times= Result[1];out.write (' %d%d%d'%(Game_times,min_times,total_times)); Out.close ();#Calculate AverageAvg_times =0;ifgame_times!=0:avg_times= Float (game_times)/Total_times;#what is output after the endPrint('you have played%d rounds, of which the fastest%d guesses, the average number of rounds is%.2f, a total of%d games. '% (game_times,min_times,avg_times,total_times));
In fact, there is nothing to write, because the grammar and so on to look at the manual what is good, write it is also not interesting, not commonly used also remember, really learn quickly forget also fast, can only remember the core of things.
Learn python to see this tutorial: http://crossincode.com/course/lesson_list/pretty good, looked at the day.
Python Learning Notes