import re # Function to check sentence structure def check_sentence_structure(sentence): errors = [] # Check if the sentence starts with a capital letter if not sentence[0].isupper(): errors.append("Sentence should start with a capital letter.") # Check if the sentence ends with a period if not sentence.endswith('.'): errors.append("Sentence should end with a period.") # Check for subject-verb agreement (basic check) if "is" in sentence.lower() and "are" in sentence.lower(): errors.append("Check subject-verb agreement.") return errors # Function to teach grammar rules def teach_grammar_rules(): print("\n--- Basic English Grammar Rules ---") print("1. Every sentence should start with a capital letter.") print("2. Every sentence should end with a period (.), question mark (?), or exclamation mark (!).") print("3. Subject and verb must agree in number (e.g., 'He is' vs 'They are').") print("4. Use proper punctuation and spacing.") print("5. Avoid run-on sentences.") print("\nLet's practice some sentences!\n") # Function to practice grammar def practice_grammar(): print("Enter sentences to check their grammar. Type 'exit' to quit.") while True: sentence = input("\nEnter a sentence: ") if sentence.lower() == 'exit': print("Exiting practice mode. Goodbye!") break errors = check_sentence_structure(sentence) if errors: print("\nGrammar Errors Found:") for error in errors: print(f"- {error}") else: print("No grammar errors found. Great job!") # Main function def main(): print("Welcome to the Grammar Book Tool!") while True: print("\nMenu:") print("1. Learn Grammar Rules") print("2. Practice Grammar") print("3. Exit") choice = input("Choose an option (1/2/3): ") if choice == '1': teach_grammar_rules() elif choice == '2': practice_grammar() elif choice == '3': print("Thank you for using the Grammar Book Tool. Goodbye!") break else: print("Invalid choice. Please try again.") # Run the program if __name__ == "__main__": main() Welcome to the Grammar Book Tool! Menu: 1. Learn Grammar Rules 2. Practice Grammar 3. Exit Choose an option (1/2/3): 1 --- Basic English Grammar Rules --- 1. Every sentence should start with a capital letter. 2. Every sentence should end with a period (.), question mark (?), or exclamation mark (!). 3. Subject and verb must agree in number (e.g., 'He is' vs 'They are'). 4. Use proper punctuation and spacing. 5. Avoid run-on sentences. Let's practice some sentences! Menu: 1. Learn Grammar Rules 2. Practice Grammar 3. Exit Choose an option (1/2/3): 2 Enter sentences to check their grammar. Type 'exit' to quit. Enter a sentence: this is a test sentence Grammar Errors Found: - Sentence should start with a capital letter. - Sentence should end with a period. Enter a sentence: This is a correct sentence. No grammar errors found. Great job! Enter a sentence: exit Exiting practice mode. Goodbye!