Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- # Filename: to_title_case.py
- # Version: 1.0.0
- # Author: Jeoi Reqi
- """
- Description:
- This script converts input text to Title Case, where the first letter of each word is capitalized.
- The converted text is then saved to a file named "converted_title_case.txt" in UTF-8 encoding.
- Requirements:
- - Python 3.x
- Functions:
- - to_title_case(text): Converts input text to Title Case.
- Parameters:
- text (str): The input text to be converted.
- Returns:
- str: The text converted to Title Case.
- Usage:
- Run the script and provide the text you want to convert when prompted.
- The converted text will be saved to "converted_title_case.txt" in the same directory as the script.
- Example Output:
- Input Text: "this is a test of case converting"
- Converted Text Has Been Saved To: 'converted_title_case.txt'.
- Converted Text:
- This Is A Test Of Case Converting
- """
- def to_title_case(text):
- """
- Converts input text to Title Case.
- Parameters:
- text (str): The input text to be converted.
- Returns:
- str: The text converted to Title Case.
- """
- words = text.split()
- title_case_words = [word.capitalize() for word in words]
- return ' '.join(title_case_words)
- def main():
- """
- Main function of the script.
- Prompts the user to input text, converts it to Title Case,
- and saves the converted text to a file named "converted_title_case.txt".
- """
- input_text = input("Enter the text you want to convert to Title Case: ")
- title_case_with_spaces_text = to_title_case(input_text)
- with open("converted_title_case.txt", "w", encoding="utf-8") as file:
- file.write(title_case_with_spaces_text)
- print(f"\nConverted Text Has Been Saved To: 'converted_title_case.txt'.\n\nConverted Text:\n\t\t{title_case_with_spaces_text}")
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement