Function to Verify Alphabetic Characters - Python Programming Exercise

In this exercise, you will develop a Python program that includes a function to determine if a given character is alphabetic (from A to Z). This exercise is perfect for practicing function definition, conditional statements, and character checking in Python. By implementing this function, you will gain hands-on experience in handling function definitions, conditional statements, and character checking in Python. This exercise not only reinforces your understanding of functions but also helps you develop efficient coding practices for managing user interactions.

 Category

Mastering Functions

 Exercise

Function To Verify Alphabetic Characters

 Objective

Develop a Python program that includes a function to determine if a given character is alphabetic (from A to Z). The function can be used to check if a character like 'a' is alphabetic, and if so, the program will print a message saying 'It is an alphabetic character'. Remember, you don't need to consider accented characters or 'ñ'.

 Example Python Exercise

 Copy Python Code
# Function to check if a given character is alphabetic (from A to Z)
def is_alphabetic(char):
    # Check if the character is alphabetic (between 'a' and 'z' or 'A' and 'Z')
    if char.isalpha() and len(char) == 1:
        return True
    else:
        return False

# Example usage of the is_alphabetic function
def main():
    # Take a character input from the user
    char = input("Enter a character: ")

    # Check if the input character is alphabetic
    if is_alphabetic(char):
        print(f"It is an alphabetic character.")
    else:
        print(f"It is not an alphabetic character.")

# Run the main function if the script is executed directly
if __name__ == "__main__":
    main()

 Output

Enter a character: a
It is an alphabetic character.
Enter a character: 1
It is not an alphabetic character.

 Share this Python Exercise

 More Python Programming Exercises of Mastering Functions

Explore our set of Python Programming Exercises! Specifically designed for beginners, these exercises will help you develop a solid understanding of the basics of Python. From variables and data types to control structures and simple functions, each exercise is crafted to challenge you incrementally as you build confidence in coding in Python.