📘 Python Crash Course – Chapter 2: Variables and Simple Data Types – Exercise 2-8 Solution
Welcome to another solution from Python Crash Course by Eric Matthes.
📝 Exercise 2-8
Task:Write addition, subtraction, multiplication, and division
operations that each result in the number 8 . Be sure to enclose your operations
in print statements to see the results . You should create four lines that look
like this:
print(5 + 3)
Your output should simply be four lines with the number 8 appearing once
on each line
✅ Solution Code:
print(5+3)
print(11-3)
print(4*2)
print(16/2)
This Python code demonstrates basic arithmetic operations (addition, subtraction, multiplication, and division) that all result in the number 8. Here's how it works:
-
Addition:
The expression
5 + 3
adds 5 and 3, resulting in 8. The result is printed using theprint()
function. -
Subtraction:
The expression
11 - 3
subtracts 3 from 11, resulting in 8. The result is printed. -
Multiplication:
The expression
4 * 2
multiplies 4 by 2, resulting in 8. The result is printed. -
Division:
The expression
16 / 2
divides 16 by 2, resulting in 8. The result is printed.
This code demonstrates how to perform basic arithmetic operations in Python and use the print()
function to display the results.
🔍 Output:
8
8
8
8.0
📚 Related Exercises from Chapter 2:
- ➤ Exercise 2-1 | Simple Message Part 1
- ➤ Exercise 2-2 | Simple Messages Part 2
- ➤ Exercise 2-3 | Personal Message
- ➤ Exercise 2-4 | Name Cases
- ➤ Exercise 2-5 | Famous Quote
- ➤ Exercise 2-6 | Famous Quote 2
- ➤ Exercise 2-7 | Stripping Names
- ➤ Exercise 2-8 | Number Eight
- ➤ Exercise 2-9 | Favorite Number
- ➤ Exercise 2-10 | Adding Comments
- ➤ Exercise 2-11 | Zen of Python
🔗 Connect With Us:
“The only way to learn a new programming language is by writing programs in it.”
– Dennis Ritchie
📌 Tags: #Python #PythonCrashCourse #CodingForBeginners #LearnPython #PythonProjects #PythonTips