The For Loop will loop for every value you have in a list. Here is a sample: #!/usr/local/bin/python for letter in “James”: print letter This code will loop until every letter of James is printed out, like so: J A M E S Pretty simple right? Let's involve the user more: #!/usr/local/bin/python user_name = raw_input(“Enter your name: “) for letter in user_name: print letter If the users name is something like Javier, it will print out: J A V I E R And that is it for loops in Python. There are no Do While loops as in other languages. Conditional Statements Sometimes in programming you need to ask certain questions and have the program respond accordingly. You can do so with conditional statements. Basically the way they work is this: "If this, then that." They get more complicated of course. You also can say "If this happens, do this, else do that." Or even "If this and That, or This or That, then do this else do that or that." I hope that is confusing, because this is the end of the article, and I want to ensure you return to enlighten yourself when I write the next episode on Python Conditionals. Till then...
blog comments powered by Disqus |
|
|
|
|
|
|
|