Learn with Yasir

Share Your Feedback

Python While Loop Exercises - Practice Problems & Solutions


๐Ÿงช Coding Exercises

๐ŸŸข Beginner Exercises

  1. Age and Exercise Input Validation
  2. Create a program that:
    1. Validates age input (must be positive number)
    2. Gets user's name
    3. Validates exercise preference (only accepts Y/N)
    4. Prints all collected information
    

    Requirements

    • Use `while True` loops for input validation
    • For age: reject non-numeric and non-positive values
    • For exercise preference: accept only Y or N (case insensitive)
    • Display formatted output with name and age
    • Handle all edge cases (empty input, wrong types, etc.)

    Input

    (Program should handle console input interactively)
    Example test sequence:
    Enter your age: abc
    Enter your age: -5
    Enter your age: 25
    Enter your name: Alice
    Do you like to exercise? (Y/N): maybe
    Do you like to exercise? (Y/N): N
    

    Expected Output

    Your name is Alice and you are 25 years old.
    
    Nice
    

    ๐Ÿ“š View Solution



๐ŸŸก Intermediate Exercises


๐Ÿ”ด Advanced Exercises



๐Ÿง  Practice & Progress

Explore More Topics

Python Fundamentals

Flow Control Statements


Python Functions


Fundamentals more ...




๐Ÿง  Python Advanced

Object-Oriented Programming in Python (OOP)

More...

๐Ÿง  Modules