FOUNDATIONS OF PROGRAMMING : INTRODUCTION TO PROGRAMMING : 01.03 PRINTING STRINGS
Post Mortem Review (PMR)
Professional programmers develop a strong habit for success early on: the Post Mortem Review (PMR). This PMR is a short, written statement that evaluates how the project went, reflecting on what went well and how the program could be improved. This allows programmers to share lessons learned and become more efficient and effective during future projects. What was the purpose of your program? The purpose of my program was to say "Happy Birthday" to my sister. It also gave me a chance to practice my Python skills. How could your program be useful in the real world? I'm going to show it to my sister on her birthday. It'll be like a birthday card that I programmed. What is a problem you ran into, and how did you fix it? I kept typing 'Happy Birthday' without the quotation marks, and it wouldn't work. When I realized I had my syntax wrong, I fixed it and it worked. Describe one thing you would do differently the next time you write a program. I learned that it is important to pace myself and pay attention to details. When I got the syntax wrong, I learned what happens when I don't use the quotation marks. Now I know I need to pay attention to my code so I don't leave out important information.
The print() function
The print() function in Python is used any time you want your program to display something to the screen (which is often, unless you're a fan of blank screens).
logic errors
These are also called semantic errors, and they can be pretty tricky to fix. Logical errors mean the program ran, but the results were not as expected. The program's syntax is fine, so there's no error. You have to notice these problems on your own by checking to see what happens when you run the program. If you didn't get what you expected, then you have to go back through to code to figure out why! Error: print("Grass is purple.") Fix: print("Grass is green.")
syntax error
These are the easiest and most common errors. A syntax error occurs when you've broken a programming language rule. Written languages have rules, such as spelling, grammar, and punctuation. Error: This sentence shouldnt have eny errors Correction: This sentence shouldn't have any errors. Programming languages have rules for their structure, too. In Python, the quotation marks and parentheses are required syntax to print a string literal. If you forget to use them, the computer won't know what to do. Error: print Hello, World! Correction: print("Hello, World!")
runtime errors
These happen when you run the program. Usually this means there's a problem with a value, and the computer can't finish doing what you requested. An example would be division by 0. The computer doesn't know how to do that any better than your math teacher! Error: print( 11 / 0 ) Correction: print( 11 / 17 )
string literal
To make Python print your strings exactly as you wrote them, you must put them in quotation marks. A string within quotation marks is called a string literal.
print Statement
statement: print("Are you having fun yet?") Output: Are you having fun yet?
GRACE HOPPER
GRACE HOPPER (1906 - 1992) Most Likely to Coin a Term Much deserving of this title, Grace is credited for popularizing the term "debugging" as well as "compiler" (she also created the first compiler). She is also known as "Amazing Grace" for her obvious contributions to programming, as well as her work as a U.S. Navy Rear Admiral.
Troubleshooting Tips
If you're still stuck, take a quick look at these troubleshooting tips: Check your spelling and capitalization - Python is case sensitive! Check your punctuation - Is there a quote or parenthesis missing? Check your spacing - Python expects blocks of code to be spaced properly. Look out for those indentations. Check before and after - Sometimes the error is hiding in the line above or below. Talk it out - Read the code out loud to yourself. Really! It should read like a (really weird) story. Once you say it out loud, your ears may hear the bug.
string
In programming, a string is a sequence of letters, numbers, spaces, and symbols or alphanumeric information. A string could be a single letter, a word, or even a phrase. To make Python print your strings exactly as you wrote them, you must put them in quotation marks. A string within quotation marks is called a string literal. Why? Because Python will print literally what you type, no matter what. Roll over the code below to see how the print() function is used. print("This will print!") This Python statement tells your computer to display the phrase This will print! because the print() function instructions are built into Python
