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.

Find the smallest and largest word from a string

In this program, we will take a string as input and find the smallest and largest word in a given string

Steps to solve the program
  1. Take a string as input.
  2. Split the string using Split().
  3. Find the smallest and the largest word from a string using min() and max().
				
					#Input string
string = "Learning is a part of life and we strive"

#Printing output
print("Longest words: ",max(string.split(" "),key=len))
print("Smallest word: ",min(string.split(" "),key=len))
				
			

Output :

				
					Longest words:  Learning
Smallest word:  a
				
			

get common words from strings.

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

Get common words from strings

In this program, we will take two strings as input and get common words from strings.

Steps to solve the program
  1. Take two strings as input and create an empty list.
  2. Using For loop find the common words from strings and add them to the empty list.
  3. Convert the list into a string Join().
  4. Print the output.
				
					#Input strings
string1 = "Very Good Morning, How are You"
string2 = "You are a Good student, keep it up"
List = []

for word in string1.split(" "):
    if word in string2.split(" "):
        List.append(word)

#Printing output        
" ".join(List)
				
			

Output :

				
					'Good are You'
				
			

find the longest capital letter word from the string.

find the smallest and largest word in a given string.

Find the longest capital letter word from string

In this program, we will take a string as input and find the longest capital letter word from the string

Steps to solve the program
  1. Take a string as input.
  2. Import re library to find the all capital letter words.
  3. Find the longest capital letter word from the string using max(),
  4. Print the output.
				
					#Importing re
import re

#Input string
string="Learning PYTHON programming is FUN"

#Finding all capital letters words
word = re.findall(r"[A-Z]+", string)

#Printing output
print(max(word, key=len))
				
			

Output :

				
					PYTHON
				
			

remove unwanted characters from the given string.

get common words from strings.