Exercise 2-8 Solution – Python Crash Course Chapter 2: Variables and Simple Data Types

 

📘 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:

  1. Addition:

    The expression 5 + 3 adds 5 and 3, resulting in 8. The result is printed using the print() function.

  2. Subtraction:

    The expression 11 - 3 subtracts 3 from 11, resulting in 8. The result is printed.

  3. Multiplication:

    The expression 4 * 2 multiplies 4 by 2, resulting in 8. The result is printed.

  4. 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:


🔗 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

Previous Post Next Post

Contact Form