Search the courses, subjects, tracks, games and features, or jump straight to a page.
Learn it your way
A short class with Sarah and her students. The other ways are under More.
Sign up free to listen. Transcripts are free to read.
Today, we will discuss how to use the print() function to show numbers on the screen. Can someone tell me what you might want to print in a program?
We could print the results of calculations.
Exactly! Let's demonstrate that with an example. If I type print(10), what do you think is the output?
It should output 10.
Correct! Now, how about printing a calculation, for instance, print(5 + 3)?
That would display 8.
Exactly! You're catching on very well. Remember, this process helps visualize the output of our calculations.
Now that we've established how to print numbers, let’s explore printing expressions. What do you think happens when we perform an expression inside the print function?
It evaluates the expression and prints out the result.
That's right! Let’s test that. What would you expect from print(10 * 2)?
It will print 20 since that's the result of multiplying 10 and 2.
Well done! It's important to use print() effectively to convey results clearly. Let's recap this: printing expressions allows for immediate feedback on calculations.
So far, we have seen how print() outputs numbers and expressions. Let’s clarify! If I wrote print(7) and then print(10 + 5), what outputs would we get?
The first one would be 7 and the second would output 15.
Exactly! And it's important to remember that each call to print() will start on a new line unless you specify otherwise. Why is that useful?
Because it helps us read the output more clearly!
Absolutely! Clear output is essential for debugging and making the program user-friendly. Great job today!
Term
What does the print() function do?
Click to flip
Term
How do you print an expression?
Click to flip
This section discusses how to use the print() function in Python to display numbers and solve arithmetic expressions.
In this section, students will learn to utilize the print() function to output numbers and evaluate arithmetic expressions. The examples illustrate how to display results directly in Python, outlining the significance of output in programming.
The print() function in Python is fundamental for displaying output to the user. This section emphasizes the function's ability to print numerical values and the results of arithmetic expressions, vital for both debugging and user interaction in programming.
Printing a single number:
print(10)Output: 10
Printing the result of an expression:
print(5 + 3)Output: 8
Through understanding these capabilities, programmers can effectively communicate computations and outputs to users, thus enhancing their software usability.