Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- # Filename: to_camel_case.py
- # Version: 1.0.0
- # Author: Jeoi Reqi
- """
- Description:
- This script converts input text to Camel Case, where the case of each letter alternates,
- starting with uppercase for the first letter. Spaces and other non-alphabetic characters
- are preserved in the original position.
- The converted text is then saved to a file named "converted_camel_case.txt" in UTF-8 encoding.
- Requirements:
- - Python 3.x
- Functions:
- - to_camel_case(text): Converts input text to Camel Case.
- Parameters:
- text (str): The input text to be converted.
- Returns:
- str: The text converted to Camel Case.
- Usage:
- Run the script and provide the text you want to convert when prompted.
- The converted text will be saved to "converted_camel_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_camel_case.txt'.
- Converted Text:
- ThIs Is A TeSt Of CaSe CoNvErTiNg
- """
- def to_camel_case(text):
- """
- Convert a given string to Camel Case where each letter's case alternates,
- starting with uppercase.
- Parameters:
- text (str): The input string.
- Returns:
- str: The Camel Case converted string.
- """
- result = []
- upper = True
- for char in text:
- if char.isalpha():
- if upper:
- result.append(char.upper())
- else:
- result.append(char.lower())
- upper = not upper
- else:
- result.append(char)
- return ''.join(result)
- def main():
- """
- Main function to prompt user input and convert the text to Camel Case.
- The converted text is saved to a file.
- """
- input_text = input("Enter the text you want to convert to Camel Case: ")
- camel_case_text = to_camel_case(input_text)
- with open("converted_camel_case.txt", "w", encoding="utf-8") as file:
- file.write(camel_case_text)
- print("\nConverted Text Has Been Saved To: 'converted_camel_case.txt'.\n")
- print("Converted Text:\n")
- print(f"\t\t{camel_case_text}")
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement