10-Program
10-Program
def remove_punctuations(input_string):
Additional Clarity for the written Program, only for understanding, not for writing:
1. Function Definition
def remove_punctuations(input_string):
- The function is defined to take a string input and remove all punctuation marks.
2. Punctuation List
punctuations = '''!()-[]{};:'"\,<>./?@#$%^&*_~'''
- This variable stores common punctuation marks to compare against.
3. Initialize Resultant String
no_punct = ""
- An empty string is initialized to hold the resultant string without punctuations.
4. Iterating Through the Input String
for char in input_string:
- Loops through each character in the input string.
5. Check for Punctuation
if char not in punctuations:
- This condition checks if the character is not in the list of punctuations.
6. Append Non-Punctuation Characters
no_punct += char
- Adds the non-punctuation character to the result string.
7. Return Resultant String
return no_punct
- Returns the string after all punctuations are removed.
8. Take User Input
user_input = input("Enter a string: ")
- Takes a string input from the user.
9. Call the Function and Display the Result
result = remove_punctuations(user_input)
print("String without punctuations:", result)
- Calls the function and prints the result.
Additional Clarity for the written Program, only for understanding, not for writing:
1. Function Definition
def reverse_string(input_string):
o This function takes a string as input (input_string).
o It will return the reversed version of the input string.
2. Reversing the String
reversed_string = input_string[::-1]
o The slicing technique [::-1] is used to reverse the string.
▪ : selects all characters.
▪ -1 indicates the step to traverse the string in reverse.
3. Returning the Result
return reversed_string
o The reversed string is returned to the caller.
4. Taking User Input
user_input = input("Enter a string: ")
o The program prompts the user to input a string.
5. Calling the Function
result = reverse_string(user_input)
o The input string is passed to the reverse_string function, and the result is
stored in the variable result.
6. Displaying the Result
print("Reversed string:", result)
o The reversed string is printed.