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

 

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

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


πŸ“ Exercise 7-2

Task:
Store a message in a variable, and then print that message.

✅ Solution Code:


members = int(input("How many people are in your dinner group? "))
if members > 8:
    print("You'll have to wait for a table.")
else:
    print("Your table is ready.")

🧠 Code Explanation:

  1. Prompt the user for input:

    The input() function is used to ask the user how many people are in their dinner group. The input is converted to an integer using the int() function and stored in the variable members.

  2. Check the group size:

    An if statement checks whether the number of members in the group is greater than 8. This condition determines whether a table is immediately available or if the group needs to wait.

  3. Display appropriate messages:

    • If the group size is greater than 8, a message is displayed indicating that they will have to wait for a table.
    • If the group size is 8 or fewer, a message is displayed indicating that their table is ready.

πŸ” Output 1


How many people are in your dinner group? 7
Your table is ready.

πŸ” Output 2


How many people are in your dinner group? 10
You'll have to wait for a table.

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