Print characters at odd places in a string.

In this program, we will take a string as input and print characters at odd places in a string.

Steps to solve the program
  1. Take a string as input.
  2. Use the range function to find the odd places from the length of the string.
  3. Print only those characters at odd places in a string using Indexing.
				
					#Input string
string = "abcdefg"

for i in range(len(string)):
    if i%2 != 0:
    #Printing output
        print(string[i],end="")
				
			

Output :

				
					bdf
				
			

count the number of consonants in a string.

remove all duplicate characters from a given string

Count the number of consonants in a string.

In this program, we will take a string as input and count the number of consonants in a string.

Steps to solve the program
  1. Take a string as input.
  2. Create a list containing all the vowels and a count variable and assign its value equal to zero.
  3. Use For loop to iterate over each character of the string.
  4. If the character is not in the vowels list add 1 to the count variable.
  5. Print the output.
				
					#Input string
string = "sqltools"
vowel = ["a","e","i","o","u","A","E","I","O","U"]
count = 0

for char in string:
    if char not in vowel:
        count += 1

#Printing output
print("Number of consonants: ",count)
				
			

Output :

				
					Number of consonants:  6
				
			

count the number of vowels in a string.

print characters at odd places in a string.

Count the number of vowels in a string

In this program, we will take a string as input and count the number of vowels in a string.

Steps to solve the program
  1. Take a string as input.
  2. Create a list containing all the vowels and a count variable and assign its value equal to zero.
  3. Use For loop to iterate over each character of the string.
  4. If the character is a vowel add 1 to the count variable.
  5. Print the output.
				
					#Input string
string = "I am learning python"
vowel = "aeiou"
count=0

for char in string:
    if char.lower() in vowel:
        count += 1
        
#Printing output
print("Number of vowels: ",count)
				
			

Output :

				
					Number of vowels:  6
				
			

check if a string has a number or not.

count the number of consonants in a string.

Check if a string has a number or not

In this program, we will take a string as input and check if a string has a number or not.

Steps to solve the program
  1. Take a string as input.
  2. Create a count variable and assign its value equal to 0.
  3. Use for loop to iterate over each character of the string.
  4. If the character is a number add 1 to the count variable.
  5. Use isnumeric() to check for numbers.
  6. If in the end count is greater is 0 then the string has a number.
  7. Print the output. 
				
					#Input string
string = "python1"
count = 0

for char in string:
    if char.isnumeric():
        count += 1
        
#Checking for numbers
if count > 0:
    print("Given string have a number")
else:
    print("Given string does not have a number")
				
			

Output :

				
					Given string have a number
				
			

print characters at even places in a string.

count the number of vowels in a string.

Print characters at even places in a string.

In this program, we will take a string as input and print characters at even places in a string.

Steps to solve the program
  1. Take a string as input.
  2. Use the range function to find the even places from the length of the string.
  3. Print only those characters at even places in a string using Indexing.
				
					#Input string
string ="sqatools"

for i in range(len(string)):
    if i%2 == 0:
    #Printing output
        print(string[i], end = "")
				
			

Output :

				
					saol
				
			

combine two strings into one.

check if a string has a number or not.

Combine two strings into one.

In this program, we will take two strings as input and combine two strings into one.

Steps to solve the program
  1. Take two strings as inputs.
  2. Combine them using “+” operator.
  3. Print the output.
				
					#Input string
string1 = "abc"
string2 = "def"

#Printing output
print(string1 + string2)
				
			

Output :

				
					abcdef
				
			

calculate the frequency of each character in a string.

print characters at even places in a string.

Calculate frequency of each character in string

In this program, we will take a string as input and calculate the frequency of each character in a string.

Steps to solve the program
  1. Take a string as input and create an empty dictionary.
  2. Use For loop to iterate over each character in the string.
  3. Add the character as a key in the dictionary and its count in the string as its value.
  4. Use count() to count how many times a character has appeared in the string.
  5. Print the output.
				
					#Input string
string = "sqatools"
dictionary = dict()

for char in string:
    dictionary[char] = string.count(char)

#Printing output    
print(dictionary)
				
			

Output :

				
					{'s': 2, 'q': 1, 'a': 1, 't': 1, 'o': 2, 'l': 1}
				
			

calculate the length of a string.

combine two strings into one.

Calculate the length of string

In this program, we will take a string as input and calculate the length of string.

Steps to solve the program
  1. Take a string as input.
  2. Use the in-built len function to calculate the length of the string.
  3. Prin the output.
				
					#Input string
string="python"

#Printing output
print(len(string))
				
			

Output :

				
					6
				
			

reverse the words in a string.

calculate the frequency of each character in a string.

Reverse the words in a string

In this program, we will take a string as input and reverse the words in a string.

Steps to solve the program
  1. Take a string as input.
  2. Split the string using Split().
  3. Reverse the splitter string using Indexing.
  4. Join the reversed words using join().
  5. Print the output.
				
					#Input string
string="sqatools python"

#Printing output
print(" ".join(string.split(" ")[::-1]))
				
			

Output :

				
					python sqatools
				
			

Check whether the given string is a palindrome (similar) or not.

calculate the length of a string.

Given string is a palindrome or not.

In this program, we will take a string as input and check whether the given string is a palindrome (similar) or not

Steps to solve the program
  1. Take a string as input.
  2. Create a variable and assign its value equal to the given string in reverse order.
  3. Check whether both the strings are equal or not using the if else statement.
  4. Print the output.
				
					#Input strings
string ="sqatoolssqatools"
string2 = string[::-1]

#Printing output
if string == string2:
    print("Given string is a palindrome")
else:
    print("Given string is not a palindrome")
				
			

Output :

				
					Given string is not a palindrome
				
			

find the smallest and largest word in a given string.

reverse the words in a string.