Python is a fast, flexible, beginner-friendly programming language. It’s gradual learning curve and readability make it an excellent choice for launching your adventures in coding. Python is also amazingly powerful. NASA, Google and Disney, to name a few, use it for everything from web applications to robots. Take a byte of Python and quickly learn to think like a programmer with our free videos and tutorials.
I’m guessing you’re learning Python because you want to write interactive programs, like video games. Well, today is your lucky day. You’re going to program your first Python game. Your First Python Game: Rock, Paper, Scissors Open IDLE and create a new file, rps.py. Then enter the following: Experienced programmers will be very quick to point out that there are …
While loops are useful when we want to maintain a state until a certain condition is met or until some external event occurs. But they can also get out of hand. Programming is like a circus: you gotta keep the lions in the ring. Or pythons in the loop. It might seem simple, but Python loop control is very important …
Did you play Red Light/Green Light growing up? I did. I still play it, though it’s hard to find adults willing to join me. If you live outside the United States you probably played a version called Statues. But what does this have to do with Python while loops? Allow me to explain… To play Red Light/Green Light, you and …
Did you ever play Snakes & Ladders? We had the tame version in America, Chutes and Ladders. It was supposed to teach you morals. But let’s use it to illustrate our next concept: Python elif statements. The elif statement is a portmanteau of else and if. A portmanteau is any word that is a mash-up of two other words. We …
When I was a young whippersnapper, I didn’t get dessert unless I finished my dinner. Dinner always consisted of healthy stuff like spinach so it was very hard to finish. That was my introduction to conditional statements. Conditional statements are like saying, “If this, then that.” If I ate dinner, then I got dessert. In my example, eating dinner is …
True or False? You use some combination of these opposite pairs everyday: Yes. No. Up. Down. Left. Right. Forward. Back. On. Off. If your answer is True, then you’re already a computer scientist! Why stay inside learning Boolean logic? You can stop reading now and go outside and play. Boolean Logic What? You’re still reading? You want to know more? …
Writing Python Functions: Flow The Python interpreter reads a program just like you are reading this page: one line at a time, from left to right and top to bottom. The interpreter executes operations and functions in the order that it encounters them. This is called control flow or the flow of execution. Unlike the Python interpreter, when we read …
Python’s built-in functions are incredibly useful. Eventually you will find yourself repeating yourself. That’s bad. That’s when programming gets boring. Fortunately, you can write your own functions, which is why the first three letters of function are ‘F-U-N’. Writing Python Functions Now that we’re writing functions, you will want to use IDLE to create new files. It becomes tedious very …
Functions are like little machines in your program. You put something in the machine, press the start button, it works its magic and spits something out. Python functions are incredibly useful. They allow us to reuse code and simplify our programs. The last thing you want to do is waste your time rewriting the same thing over and over. Remember …
Life is like a Python list. You spend most of it in boxes. Sometimes the box is empty and sometimes the box is filled with different objects. And sometimes it’s a box within a box. I like to think of Python lists as boxes because the brackets look like a container. We make an empty box, or list, like this: …