Python : For Loops & String center( ) Method

Turtle Race.PNG

Turtle Race - Project 1

Introduction: This project introduces for loops through a fun turtle race game. Loops are used to draw the race track and to make the turtles move a random number of steps in each turn. If you have a group of people to play the game, each person picks a turtle and the one that gets the furthest is the winner.  

A ‘for loop’ is used for iterating over a sequence (that is either a list, a tuple, a dictionary, a set, or a string).This is less like the for keyword in other programming languages, and works more like an iterator method as found in other object-orientated programming languages.With the ‘for loop’ we can execute a set of statements, once for each item in a list, tuple, set etc. The center() method will center align the string, using a specified character (space is default) as the fill character.

Syntax:  string.center(length, character)

Share on facebook
Facebook
Share on twitter
Twitter
Share on linkedin
LinkedIn
Share on pinterest
Pinterest
Categories

Leave a Reply

Your email address will not be published. Required fields are marked *