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

 

πŸ“˜ Python Crash Course – Chapter 2: Variables and Simple Data Types – Exercise 2-10 Solution

Welcome to another solution from Python Crash Course by Eric Matthes.


πŸ“ Exercise 2-10

Task:Choose two of the programs you’ve written, and add at least one comment to each . If you don’t have anything specific to write because your programs are too simple at this point, just add your name and the current date at the top of each program file . Then write one sentence describing what the program does

✅ Solution Code:


# i choose exercise 2.9 
no=10  # this is my fav no 
msg="My favourite no is"   #this is mesage 
print(f"{msg} {no}")  

🧠 Code Explanation:

This Python code demonstrates how to add comments to a program and includes an example of storing and printing a favorite number. Here's how it works:

  1. Add comments:

    Comments are added to the code using the # symbol. These comments explain what each part of the code does. For example:

πŸ” Output:


My favourite no is 10

πŸ“š 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

“In the world of code, Python is the language of simplicity, where logic meets creativity, and every line brings us closer to our goals.”— Only Python

πŸ“Œ Follow Us And Stay Updated For Daily Updates

Comments