Total number of special characters in a string

In this program, we will find the total number of special characters in a string.

Steps to solve the program
  1. Take a string as input and create another string of special characters.
  2. Create a variable to count the total number of special characters in a string.
  3. Use for loop to iterate over each character of the input string.
  4. If that character is in the string containing special characters then add 1 to the variable that we have created.
  5. Print the output.
				
					str1 = '@sqa#tools!!'
special_char = '!@#$%^&*()_{[}]'
special = 0

for char in str1:
    if char in special_char:
        special += 1
        
print("Special character: ",special)
				
			

Output :

				
					Special character:  4
				
			

print the days in a week except Sunday using a while loop

add even numbers in an empty list from a given list

Leave a Comment