id
int64
0
25.6k
text
stringlengths
0
4.59k
7,700
line is the first line beyond the while-block that started on line this code is executed when the execution breaks out of that while loop from line or at this pointthe game is over now the program should print the board and scores and determine who won the game getscoreofboard(will return dictionary with keys 'xand 'oa...
7,701
def drawboard(board) this function prints out the board that it was passed returns none hline ++ print( ' print(hline for in range( ) print('% |( + )end='' for in range( ) print(board[ ][ ]end='' print('|' print(hlinesummary the ai may seem almost unbeatablebut this isn' because the computer is smart the strategy it fo...
7,702
reversi ai simulation topics covered in this simulations percentages pie charts integer division the round(function "computer vs computergames the reversi ai algorithm was simplebut it beats me almost every time play it this is because the computer can process instructions fastso checking each possible position on the ...
7,703
making the computer play against itself save the old reversi py file as aisim py by clicking on file save asand then entering aisim py for the file name and clicking ok this will create copy of our reversi source code as new file that you can make changes towhile leaving the original reversi game the same (you may want...
7,704
scores getscoreofboard(mainboard print(' has % points has % points(scores[' ']scores[' ']) input('press enter to continue ' if turn =' ' ' turn othertile ' xy getcomputermove(mainboard' ' makemove(mainboard' 'xy else ' turn othertile ' xy getcomputermove(mainboard' ' makemove(mainboard' 'xy if getvalidmoves(mainboardot...
7,705
making the computer play itself several times but what if we created new algorithmthen we could set this new ai against the one implemented in getcomputermove()and see which one is better let' make some changes to the source code do the following to make aisim py click on file save as save this file as aisim py so that...
7,706
othertile ' xy getcomputermove(mainboard' ' makemove(mainboard' 'xy else ' turn othertile ' xy getcomputermove(mainboard' ' makemove(mainboard' 'xy if getvalidmoves(mainboardothertile=[] break else turn othertile display the final score scores getscoreofboard(mainboard print(' scored % points scored % points (scores[' ...
7,707
welcome to reversienter number of games to run game # scored points scored points game # scored points scored points game # scored points scored points game # scored points scored points game # scored points scored points game # scored points scored points game # scored points scored points game # scored points scored ...
7,708
there' kind of chart called pie chart which shows how much of the full total certain portion is figure - is pie chart with % % %and portions below notice that adds up to % whole pie we can calculate the percentage with division to get percentagedivide the part you have by the totaland then multiply by one hundred for e...
7,709
round( round( round( round( round( the round(function also has an optional parameterwhere you can specify to what place you want to round the number to for examplethe expression round( evaluates to and round( evaluates to displaying the statistics numgames float(numgames xpercent round(((xwins numgames ) opercent round...
7,710
game # scored points scored points game # scored points scored points game # scored points scored points game # scored points scored points skipped for brevity game # scored points scored points game # scored points scored points game # scored points scored points game # scored points scored points wins games ( %) wins...
7,711
always go for corner if available for xy in possiblemoves if isoncorner(xy) return [xy if there is no cornerreturn side move for xy in possiblemoves if isonside(xy) return [xy return getcomputermove(boardtile def getsidebestmove(boardtile) return corner moveor side moveor the best move possiblemoves getvalidmoves(board...
7,712
def getcornerworstmove(boardtile) return cornera spaceor the move that flips the least number of tiles possiblemoves getvalidmoves(boardtile randomize the order of the possible moves random shuffle(possiblemoves always go for corner if available for xy in possiblemoves if isoncorner(xy) return [xy return getworstmove(b...
7,713
comparing the random algorithm against the regular algorithm now the only thing to do is replace one of the getcomputermove(calls in the main part of the program with one of the new functions then you can run several games and see how often one algorithm wins over the other firstlet' replace ' algorithm with the one in...
7,714
game # scored points scored points wins games ( %) wins games ( %)ties for games ( %of games total as you can seewhen both players are making random movesthey each win about of the time (in the above caseo happen to get lucky and won little bit more than half of the time just like moving on the corner spaces is good id...
7,715
skipped for brevity game # scored points scored points game # scored points scored points wins games ( %) wins games ( %)ties for games ( %of games total the more accurate statistics from the thousand-games run are about the same as the statistics from the hundred-games run it seems that choosing the move that flips th...
7,716
game # scored points scored points game # scored points scored points wins games ( %) wins games ( %)ties for games ( %of games total the getcornerworstmove(still loses most of the gamesbut it seems to win few more games than getworstmove(( compared to %does taking the corner spaces when they are available really make ...
7,717
the best strategy after running several simulationsyou can determine which strategy works best with programming you can make science fair project out of simulation of any board gameand it is all because you know how to instruct the computer to do itstep by stepline by line you can speak the computer' languageand get it...
7,718
graphics and animation topics covered in this installing pygame colors and fonts in pygame aliased and anti-aliased graphics attributes the pygame font fontpygame surfacepygame rectand pygame pixelarray data types constructor functions pygame' drawing functions the blit(method for surface objects events animation so fa...
7,719
if nothing appears after you hit the enter keythen you know pygame was successfully installed if the error importerrorno module named pygame appearstry to install pygame again (and make sure you typed import pygame correctlyfigure - the pygame org website the pygame website at several other game programs made with pyga...
7,720
pygamehelloworld py import pygamesys from pygame locals import set up pygame pygame init( set up the window windowsurface pygame display set_mode(( ) pygame display set_caption('hello world!' set up the colors black ( white ( red ( green ( blue ( set up fonts basicfont pygame font sysfont(none set up the text text basi...
7,721
pygame draw rect(windowsurfacered(textrect left textrect top textrect width textrect height ) get pixel array of the surface pixarray pygame pixelarray(windowsurface pixarray[ ][ black del pixarray draw the text onto the surface windowsurface blit(texttextrect draw the window onto the screen pygame display update( run ...
7,722
figure - the "hello worldprogram first you need to import the pygame module so you can call pygame' functions you can import several modules on the same line by delimiting the module names with commas line imports both the pygame and sys modules the second line imports the pygame locals module this module contains many...
7,723
spam[ 'lifespam[ spam[ : ('universe''everything'the pygame display set_mode(and pygame display set_caption(functions set up the window windowsurface pygame display set_mode(( ) pygame display set_caption('hello world!'line creates gui window by calling the set_mode(method in the pygame display module (the display modul...
7,724
table - colors and their rgb values color rgb values black blue ( gray green lime ( purple ( red teal ( white ( yellow there are three primary colors of lightredgreen and blue by combining different amounts of these three colors (which is what your computer screen does)you can form any other color in pygametuples of th...
7,725
figure - examples of different fonts font is complete set of lettersnumberssymbolsand characters drawn in single style figure - shows the same sentence printed in different fonts in our earlier gameswe only told python to print text the colorsizeand font that was used to display this text was completely determined by y...
7,726
the font object that you've stored in the basicfont variable has method called render(this method will return surface object with the text drawn on it the first parameter to render(is the string of the text to draw the second parameter is boolean for whether or not you want anti-aliasing on line pass true to use anti-a...
7,727
the module you import is pygameand inside the pygame module are the font and surface modules inside those modules are the font and surface data types the pygame programmers made the modules begin with lowercase letterand the data types begin with an uppercase letter this makes it easier to distinguish the data types an...
7,728
pygame rect attribute myrect left table - rect attributes description integer value of the -coordinate of the left side of the rectangle myrect right integer value of the -coordinate of the right side of the rectangle myrect top integer value of the -coordinate of the top side of the rectangle myrect bottom integer val...
7,729
the pygame draw polygon(function can draw any polygon shape you give it the parametersin orderarethe surface object to draw the polygon on the color of the polygon tuple of tuples that represents the xy coordinates of the points to draw in order the last tuple will automatically connect to the first tuple to complete t...
7,730
the surface object to draw the circle on the color of the circle tuple of two integers for the xy coordinate of the center of the circle an integer for the radius (that isthe sizeof the circle optionallyan integer for the width width of means that the circle will be filled in line draws blue circle on the surface objec...
7,731
height are equal to the width and height of the textrect plus (because the left and top were moved back pixelsso you need to make up for that spacethe pygame pixelarray data type get pixel array of the surface pixarray pygame pixelarray(windowsurface pixarray[ ][ black line creates pygame pixelarray object (called pixe...
7,732
the pygame display update(function draw the window onto the screen pygame display update(in pygamenothing is actually drawn to the screen until the pygame display update(function is called this is because drawing to the screen is slow compared to drawing on the surface objects in the computer' memory you do not want to...
7,733
line has for loop to iterate over each event object in the list returned by pygame event get(if the type attribute of the event is equal to the constant variable quitthen you know the user has closed the window and wants to terminate the program pygame generates the quit event (which was imported from the pygame locals...
7,734
pygame init( set up the window windowwidth windowheight windowsurface pygame display set_mode((windowwidthwindowheight) pygame display set_caption('animation' set up direction variables downleft downright upleft upright movespeed set up the colors black ( red ( green ( blue ( set up the block data structure {'rect':pyg...
7,735
if ['dir'=upleftb['rect'left -movespeed ['rect'top -movespeed if ['dir'=uprightb['rect'left +movespeed ['rect'top -movespeed check if the block has move out of the window if ['rect'top block has moved past the top if ['dir'=upleftb['dir'downleft if ['dir'=uprightb['dir'downright if ['rect'bottom windowheightblock has m...
7,736
figure - an altered screenshot of the animation program how the animation program works in this programwe will have three different colored blocks moving around and bouncing off the walls to do thiswe need to first consider how we want the blocks to move moving and bouncing the blocks each block will move in one of fou...
7,737
figure - the diagram of how blocks will bounce creating and setting up pygame and the main window import pygamesystime from pygame locals import set up pygame pygame init( set up the window windowwidth windowheight windowsurface pygame display set_mode((windowwidthwindowheight) in this programyou'll see that the size o...
7,738
downright upleft upright we will use the keys on the number pad of the keyboard to remind us which belongs to which direction this is similar to the tic tac toe game is down and left is down and right is up and leftand is up and right howeverit may be hard to remember thisso instead use constant variables instead of th...
7,739
setting up the block data structures set up the block data structure {'rect':pygame rect( )'color':red'dir':uprightset up dictionary as data structure that represents each block / introduced dictionaries the dictionary will have the keys of 'rect(with rect object for value)'color(with tuple of three integers for value)...
7,740
inside the game loopthe blocks will move around the screen in the direction that they are going and bounce if they have hit side there is also code to draw all of the blocks to the windowsurface surface and call pygame display update(the for loop to check all of the events in the list returned by pygame event get(is th...
7,741
change the value of these attributes by the integer stored in movespeed movespeed stores how many pixels over blocks move on each iteration of the game loopand was set on line checking if the block has bounced check if the block has move out of the window if ['rect'top block has moved past the top if ['dir'=upleftb['di...
7,742
if ['rect'left block has moved past the left side if ['dir'=downleftb['dir'downright if ['dir'=upleftb['dir'upright if ['rect'right windowwidthblock has moved past the right side if ['dir'=downrightb['dir'downleft if ['dir'=uprightb['dir'upleft lines to are similar to lines to but checks if the left side of the block h...
7,743
after this linethe execution loops back to the start of the game loop and begin the process all over again this waythe blocks are constantly moving littlebouncing off the wallsand being drawn on the screen in their new positions the call to the time sleep(function is there because the computer can movebounceand draw th...
7,744
collision detection and keyboard/mouse input topics covered in this collision detection don' modify list while iterating over it keyboard input in pygame mouse input in pygame collision detection is figuring when two things on the screen have touched (that iscollided witheach other for exampleif the player touches an e...
7,745
the bouncer is represented by dictionary the dictionary has key named 'rect(whose value is pygame rect objectand key named 'dir(whose value is one of the constant direction variables like we had in last animation programas the bouncer bounces around the windowwe check if it collides with any of the food squares if it d...
7,746
set up direction variables downleft downright upleft upright movespeed set up the colors black ( green ( white ( set up the bouncer and food data structures foodcounter newfood foodsize bouncer {'rect':pygame rect( )'dir':upleft foods [ for in range( ) foods append(pygame rect(random randint( windowwidth foodsize)rando...
7,747
bouncer['rect'top +movespeed if bouncer['dir'=upleftbouncer['rect'left -movespeed bouncer['rect'top -movespeed if bouncer['dir'=uprightbouncer['rect'left +movespeed bouncer['rect'top -movespeed check if the bouncer has move out of the window if bouncer['rect'top bouncer has moved past the top if bouncer['dir'=upleftbou...
7,748
pygame display update(mainclock tick( the program will look like figure - the the bouncer square will bounce around the window when it collides with the green food squares they will disappear from the screen figure - an altered screenshot of the collision detection program importing the modules import pygamesysrandom f...
7,749
dorectsoverlap(is passed two pygame rect objects the function will return true if they do and false if they don' there is simple rule to follow to determine if rectangles collide look at each of the four corners on both rectangles if at least one of these eight corners is inside the other rectanglethen you know that th...
7,750
figure - is an example picture of rectangle and several points the points and the corners of the rectangle are labeled with coordinates point is inside the rectangle if the following four things are truethe point' -coordinate is greater than the -coordinate of the rectangle' left side the point' -coordinate is less tha...
7,751
in the previous animation programa call to time sleep( would slow down the program so that the program doesn' run too fast the problem with time sleep()is that might be too much of pause on slow computers and not enough of pause on fast computers pygame time clock object can pause an appropriate amount of time on any c...
7,752
coordinate between and the size of the windowthen the food square might be pushed outside of the window altogetherlike in figure - figure - for by rectanglehaving the top left corner at ( in by window would place the rectangle outside of the window to be insidethe top left corner should be at ( instead the third parame...
7,753
before drawing the food squarescheck if the bouncer has overlapped any of the food squares if it hasremove that food square from the foods list this waypython won' draw any food squares that the bouncer has "eatenon each iteration through the for loopthe current food square from the foods (plurallist is in the variable...
7,754
the code on lines and are similar to how we drew the white square for the player line loops through each food square in the foods list line draws the food square onto the windowsurface surface this program was similar to the bouncing program in the previous except now the bouncing square will "eatother squares it passe...
7,755
moveleft false moveright false moveup false movedown false movespeed run the game loop while true check for events for event in pygame event get() if event type =quit pygame quit( sys exit( if event type =keydown change the keyboard variables if event key =k_left or event key =ord(' ') moveright false moveleft true if ...
7,756
if event type =mousebuttonup foods append(pygame rect(event pos[ ]event pos[ ]foodsizefoodsize) foodcounter + if foodcounter >newfood add new food foodcounter foods append(pygame rect(random randint( windowwidth foodsize)random randint( windowheight foodsize)foodsizefoodsize) draw the black background onto the surface ...
7,757
setting up the window and data structures starting at line the code sets up some variables that track the movement of the bouncer set up movement variables moveleft false moveright false moveup false movedown false the four variables have boolean values to keep track of which of the arrow keys are being held down for e...
7,758
event type quit description generated when the user closes the window keydown generated when the user presses down key has key attribute that tells which key was pressed also has mod attribute that tells if the shiftctrlaltor other keys were held down when this key was pressed keyup generated when the user releases key...
7,759
table - the button attribute values and mouse button value of button mouse button left button middle button right button scroll wheel moved up scroll wheel moved down setting the four keyboard variables change the keyboard variables if event key =k_left or event key =ord(' ')moveright false moveleft true if event key =...
7,760
value for the arrow keyswhich is why we use the constant variable k_left you can use the ord(function to get the ordinal value of any single character to compare it with event key by executing the code on lines and if the keystroke was either k_left or ord(' ')you make the left arrow key and the key do the same thing t...
7,761
player height player width player top random randint( windowheight player left random randint( windowwidth you can also add teleportation to the game if the user presses the "xkeythen lines and will set the position of the user' square to random place on the window this will give the user the ability to teleport around...
7,762
if movedown is set to true (and the bottom of the player' square isn' below the bottom edge of the window)then line moves the player' square down by adding movespeed to the player' current top attribute lines to do the same thing for the other three directions the colliderect(method check if the player has intersected ...
7,763
sounds and images topics covered in this sound and image files drawing sprites the pygame image load(function the pygame mixer sound data type the pygame mixer music module in the last two we've learned how to make gui programs that have graphics and can accept input from the keyboard and mouse we've also learned how t...
7,764
figure - an example of complete scenewith sprites drawn on top of background the sprite images are drawn on top of background notice that you can flip the sprite image horizontally so that the sprites are facing the other way you can draw the same sprite image multiple times on the same window you can also resize the s...
7,765
your computer has microphoneyou can also record sounds and make your own wav files to use in your games sprites and sounds program this program is the same as the keyboard and mouse input program from the last howeverin this program we will use sprites instead of plain looking squares we will use sprite of little perso...
7,766
playerstretchedimage pygame transform scale(playerimage( ) foodimage pygame image load('cherry png' foods [ for in range( ) foods append(pygame rect(random randint( windowwidth )random randint( windowheight ) ) foodcounter newfood set up keyboard variables moveleft false moveright false moveup false movedown false move...
7,767
pygame quit( sys exit( if event key =k_left or event key =ord(' ') moveleft false if event key =k_right or event key =ord(' ') moveright false if event key =k_up or event key =ord(' ') moveup false if event key =k_down or event key =ord(' ') movedown false if event key =ord(' ') player top random randint( windowheight ...
7,768
draw the block onto the surface windowsurface blit(playerstretchedimageplayer check if the block has intersected with any food squares for food in foods[:] if player colliderect(food) foods remove(food player pygame rect(player leftplayer topplayer width player height playerstretchedimage pygame transform scale(playeri...
7,769
firstlet' set the caption of the title bar to string that describes this program on line pass the string 'sprites and soundto the pygame display set_caption(function set up the block data structure player pygame rect( playerimage pygame image load('player png' playerstretchedimage pygame transform scale(playerimage( ) ...
7,770
pygame mixer music play(- musicplaying true next you need to load the sound files there are two modules for sound in pygame the pygame mixer module can play short sound effects during the game the pygame mixer music module can play background music call the pygame mixer sound(constructor function to create pygame mixer...
7,771
toggling as what happens when you flip light switch on or offtoggling the light switch sets it to the opposite setting drawing the player on the window draw the block onto the surface windowsurface blit(playerstretchedimageplayerremember that the value stored in playerstretchedimage is surface object line draws the spr...
7,772
draw the cherries on the window draw the food for food in foodswindowsurface blit(foodimagefoodin the previous programsyou called the pygame draw rect(function to draw green square for each rect object stored in the foods list howeverin this program you want to draw the cherry sprites instead call the blit(method and p...
7,773
dodger topics covered in this the pygame fullscreen flag pygame constant variables for keyboard keys the move_ip()rect method the pygame mouse set_pos(function implementing cheat codes modifying the dodger game the last three went over the pygame module and demonstrated how to use its many features in this we'll use th...
7,774
pygame display set_mode(function is special because anything drawn on that surface object is displayed on the user' screen when pygame display update(is called pygame event event the pygame event module generates event objects whenever the user provides keyboardmouseor another kind of input the pygame event get(functio...
7,775
pygame quit( sys exit( def waitforplayertopresskey() while true for event in pygame event get() if event type =quit terminate( if event type =keydown if event key =k_escapepressing escape quits terminate( return def playerhashitbaddie(playerrectbaddies) for in baddies if playerrect colliderect( ['rect']) return true re...
7,776
drawtext('press key to start 'fontwindowsurface(windowwidth (windowheight pygame display update( waitforplayertopresskey( topscore while true set up the start of the game baddies [ score playerrect topleft (windowwidth windowheight moveleft moveright moveup movedown false reversecheat slowcheat false baddieaddcounter p...
7,777
slowcheat false score if event key =k_escape terminate( if event key =k_left or event key =ord(' ') moveleft false if event key =k_right or event key =ord(' ') moveright false if event key =k_up or event key =ord(' ') moveup false if event key =k_down or event key =ord(' ') movedown false if event type =mousemotion if ...
7,778
move the baddies down for in baddies if not reversecheat and not slowcheat ['rect'move_ip( ['speed'] elif reversecheat ['rect'move_ip( - elif slowcheat ['rect'move_ip( delete baddies that have fallen past the bottom for in baddies[:] if ['rect'top windowheight baddies remove( draw the game world on the window windowsur...
7,779
drawtext('press key to play again 'fontwindowsurface(windowwidth (windowheight pygame display update( waitforplayertopresskey( gameoversound stop(when you run this programthe game will look like figure - figure - an altered screenshot of the dodger game importing the modules import pygamerandomsys from pygame locals im...
7,780
textcolor ( backgroundcolor ( the constant variables on lines to are much more descriptive than typing out the values for examplefrom the line windowsurface fill(backgroundcoloris more understandable than windowsurface fill(( )you can easily change the game by changing the constant variables by changing windowwidth on ...
7,781
defining functions there are several functions you'll create for the game def terminate() pygame quit( sys exit(pygame requires that you call both pygame quit(and sys exit(put them both into function called terminate(now you only need to call terminate()instead of both of the pygame quit(and sys exit(functions def wait...
7,782
if playerrect colliderect( ['rect'])return true return false the playerhashitbaddie(function will return true if the player' character has collided with one of the baddies the baddies parameter is list of "baddiedictionary data structures each of these dictionaries has 'rectkeyand the value for that key is rect object ...
7,783
set up pygamethe windowand the mouse cursor pygame init( mainclock pygame time clock(line sets up the pygame by calling the pygame init(function line creates pygame time clock(object and stores it in the mainclock variable this object will help us keep the program from running too fast windowsurface pygame display set_...
7,784
set up fonts font pygame font sysfont(none line creates font object to use by calling pygame font sysfont(passing none uses the default font passing makes the font have size of points set up sounds gameoversound pygame mixer sound('gameover wav' pygame mixer music load('background mid'nextcreate the sound objects and s...
7,785
show the "startscreen drawtext('dodger'fontwindowsurface(windowwidth )(windowheight ) drawtext('press key to start 'fontwindowsurface(windowwidth (windowheight pygame display update( waitforplayertopresskey(on lines and call the drawtext(function and pass it five arguments the string of the text you want to appear the ...
7,786
at the beginningyou want to set baddies to an empty list the baddies variable is list of dictionary objects with the following keys'rectthe rect object that describes where and what size the baddie is 'speedhow fast the baddie falls down the screen this integer represents pixels per iteration through the game loop 'sur...
7,787
the game loop the game loop' code constantly updates the state of the game world by changing the position of the player and baddieshandling events generated by pygameand drawing the game world on the screen all of this happens several dozen times secondwhich makes it run in "real time while truethe game loop runs while...
7,788
indicate that the reverse cheat has been activated line checks if the "xkey has been pressed to activate the slow cheat pygame' keyboard events always use the ordinal values of lowercase lettersnot uppercase always use event key =ord(' 'instead of event key =ord(' 'otherwiseyour program may act as though the key wasn' ...
7,789
k_down down arrow k_pagedown pgdn k_escape esc k_f k_backspace backspace k_f k_tab tab k_f k_return return or enter k_f k_space space bar k_f k_delete del k_f k_lshift left shift k_f k_rshift right shift k_f k_lctrl left ctrl k_f k_rctrl right ctrl k_f k_lalt left alt k_f k_ralt right alt k_f if event type =keyupif eve...
7,790
if event key =k_escapeterminate(at any time during the gamethe player can press the esc key on the keyboard to quit line checks if the key that was released was the esc key by checking event key =k_escape if soline calls the terminate(function to exit the program if event key =k_left or event key =ord(' ')moveleft fals...
7,791
the move_ip(method for rect objects will move the location of the rect object horizontally or vertically by number of pixels for exampleplayerrect move_ip( would move the rect object pixels to the right and pixels down to move the rect object left or uppass negative values for exampleplayerrect move_ip(- - will move th...
7,792
holds reference to rect object which stores the location and size of the baddie the call to the pygame rect(constructor function has four parametersthe -coordinate of the top edge of the areathe -coordinate of the left edge of the areathe width in pixelsand the height in pixels the baddie needs to appear randomly acros...
7,793
thereforecalling playerrect move_ip(- playermoverate will change the location of playerrect by pixels to the left of its current location if moveright and playerrect right windowwidthplayerrect move_ip(playermoverate if moveup and playerrect top playerrect move_ip( - playermoverateif movedown and playerrect bottom wind...
7,794
elif reversecheatb['rect'move_ip( - if the reverse cheat is activatedthen the baddie should move up by five pixels passing - for the second argument to move_ip(will move the rect object upwards by five pixels elif slowcheatb['rect'move_ip( if the slow cheat has been activatedthen the baddie should move downwardsbut onl...
7,795
in python david mertz
7,796
by david mertz copyright ( 'reilly mediainc all rights reserved attribution-sharealike international (cc by-sa seeprinted in the united states of america published by 'reilly mediainc gravenstein highway northsebastopolca 'reilly books may be purchased for educationalbusinessor sales promotional use online editions are...
7,797
preface (avoidingflow control encapsulation comprehensions recursion eliminating loops callables named functions and lambdas closures and callable instances methods of classes multiple dispatch lazy evaluation the iterator protocol moduleitertools higher-order functions utility higher-order functions the operator modul...
7,798
what is functional programmingwe' better start with the hardest question"what is functional programming (fp)anyway?one answer would be to say that functional programming is what you do when you program in languages like lispschemeclojurescalahaskellmlocamlerlangor few others that is safe answerbut not one that clarifie...
7,799
of the name lisplists are often used with recursion on sublists as substitute for loops "purefunctional languages eschew side effects this excludes the almost ubiquitous pattern in imperative languages of assigning first onethen another value to the same variable to track the program state functional programming either...