Exercise 7-3 Solution Python Crash Course Chapter 7 : User Input And While Loops

 

πŸ“˜ Python Crash Course – Chapter 7: User Input And while loops – Exercise 7-3 Solution

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


πŸ“ Exercise 7-3

Task:
Ask the user for a number, and then report whether the number is a multiple of 10 or not

✅ Solution Code:


number = int(input("Enter a number: "))

# Check if the number is a multiple of 10
if number % 10 == 0:
    print(f"{number} is a multiple of 10.")
else:
    print(f"{number} is not a multiple of 10.")

🧠 Code Explanation:

  1. Convert user input to an integer:

    The user's input is converted to an integer using the int() function and stored in the variable number. This ensures that the input can be used for mathematical operations.

  2. Check for multiples of 10:

    An if statement checks whether the number is a multiple of 10 by using the modulus operator (%). The condition number % 10 == 0 evaluates to True if the remainder when dividing the number by 10 is 0, indicating that the number is a multiple of 10.

  3. Display appropriate messages:

    • If the condition is True, a message is displayed indicating that the number is a multiple of 10.
    • If the condition is False, the else block is executed, and a message is displayed indicating that the number is not a multiple of 10.

πŸ” Output 1


Enter a number: 5
5 is not a multiple of 10.

πŸ” Output 2


Enter a number: 100
100 is a multiple of 10.

πŸ“š Related Exercises from Chapter 7:


πŸ”— Connect With Us:

“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

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