convert half the string to uppercase.

In this program, we will take a string as input and convert half the string to uppercase.

Steps to solve the program
  1. Take a string as input.
  2. Convert the half of the string upper() and Indexing.
  3. Print the output.
				
					#Input string
str1 = "banana"

#Printing output
print(str1[:3]+str1[3:].upper())
				
			

Output :

				
					banANA
				
			

insert space before every capital letter appears in a given word

split and join a string using “-“

Number of leap years within a range of years

In this program, we will take a range of leap years as input and find the number of leap years within a range of years.

Steps to solve the program
  1. Take a range of years as input.
  2. Split the range using split() so that will get a list of starting year and ending year.
  3. Create a variable and assign its value equal to 0.
  4. Use for loop to get a range of years between starting year and the ending year.
  5. During iteration check whether a year is a leap year to not.
  6. If it is a leap year then add 1 to the variable that we created at the start.
  7. Print the output.
				
					#Input string
str1 ="1981-2001"
l = str1.split("-")
total = 0

for i in range(int(l[0]),int(l[1])+1):
    if (i % 400 == 0 or i % 100 !=0) and i % 4 == 0:
        total += 1
        
#Printing output
print("Range of years:", str1)
print("Total leap year: ",total)
				
			

Output :

				
					Range of years: 1981-2001
Total leap year:  5
				
			

extract name from a given email address

insert space before every capital letter appears in a given word

Extract the name from the email address

In this program, we will take email as string input and extract the name from the email address.

Steps to solve the program
  1. Take an email id of a student as string input.
  2. Find the index number of “@” using index().
  3. Create an empty string.
  4. Add characters from the email id to the empty string using for loop up to the index of “@”.
  5. Add only alphabets not numbers use isalpha() for this purpose.
  6. Print the output.
				
					#Input string
str1 = "student1@gmail.com"
index = str1.index("@")
str2 = ""

for char in str1[:index]:
    if char.isalpha():
        str2 += char
        
#Printing output
print(str2)
				
			

Output :

				
					student
				
			

add two strings as they are numbers

count the number of leap years within the range of years

Add two strings as they are numbers

In this program, we will take two numbers as strings and add two strings as they are numbers.

Steps to solve the program
  1. Take two numbers as a string.
  2. Add two strings after converting them into integers using int().
  3. Print the output.
				
					#Printing output
num1 = "3"
num2 = "7"

result = int(num1)+int(num2)

#Printing output
print(result)
				
			

Output :

				
					10
				
			

split a given multiline string into a list of lines

extract name from a given email address

Split a given multiline string into list of lines

In this program, we will take a multiline string as input and split a given multiline string into list of lines.

Steps to solve the program
  1. Take a multiline string as input.
  2. Split the string on a new line using split() to convert the given string into a list of lines.
  3. Print the output.
				
					#Input string
str1= "This string Contains\nMultiple\nLines"

#Printing output
print(str1.split("\n"))
				
			

Output :

				
					['This string Contains', 'Multiple', 'Lines']
				
			

extract numbers from a given string

add two strings as they are numbers

Extract numbers from a given string

In this program, we will take a string as input and extract numbers from a given string.

Steps to solve the program
  1. Take a string as input.
  2. Create an empty list.
  3. Split the given list using split().
  4. Use for loop to iterate over splitter string.
  5. If the value is a number then add it to the empty list.
  6. Print the output.
				
					#Input string
str1 = "python 456 self learning 89"
list1 = []

for char in str1.split(" "):
    if char.isdigit():
        list1.append(int(char))

#Printing output        
print(list1)
				
			

Output :

				
					[456, 89]
				
			

find the string similarity between two given strings

split a given multiline string into a list of lines

Find the string similarity between two strings

In this program, we will take two strings as input and  find the string similarity between two given strings

Steps to solve te program
  1. Take 2 strings as inputs.
  2. Import difflib library.
  3. From difflib library use SequenceMatcher to find the similarity between two strings.
  4. Print the output.
				
					#Input string
str1 = "Learning is fun in Sqatools"
str2 = "Sqatools Online Learning Platform"

import difflib
result =  difflib.SequenceMatcher(a=str1.lower(), b=str2.lower())

#Printing output
print(result.ratio())
				
			

Output :

				
					0.4
				
			

remove unwanted characters from a given string

extract numbers from a given string

Remove unwanted characters from a string.

In this program, we will take a string as input and remove unwanted characters from a given string.

Steps to remove the program
  1. Take a string as input.
  2. Create a list of unwanted characters.
  3. Using for loop check whether each character from the string belongs in the list of unwanted characters.
  4. If yes then remove the unwanted character.
  5. Print the output.
				
					#Input string
string = "sqa****too^^{ls"
unwanted = ["#", "*", "!", "^", "%","{","}"]

for char in unwanted:
    string = string.replace(char,"")

#Printing output
print(string)
				
			

Output :

				
					sqatools
				
			

count a number of non-empty substrings of a given string.

find the string similarity between two given strings

Count number of non-empty substrings of string.

In this program, we will take a string as input and count a number of non-empty substrings of a given string.

Steps to remove the program
  1. Take a string as input.
  2. Count the number of non-empty substrings using the following formula- n*n+1/2  where n is the length of the string.
  3. Print the output.
				
					#Input string
str1 = "sqatools12"

result = int(len(str1) * (len(str1) + 1) / 2)

#Printing output
print(result)
				
			

Output :

				
					55
				
			

count all the Uppercase, Lowercase, special character and numeric values in a given string

remove unwanted characters from a given string

Count all the values in a string.

In this program, we will take a string as input and count all the Uppercase, Lowercase, special character and numeric values in a given string.

Steps to solve the program
  1. Take a string as input.
  2. Create some variables and assign their values equal to 0.
  3. Use for loop to iterate over each character of the string.
  4. Check the type of the character and add 1 to the respective variable.
  5. Print the output.
				
					#Input string
str1 = "@SqaTools#lin"
upper = 0
lower = 0
digit = 0
symbol = 0

for val in str1:
    if val.isupper():
        upper += 1  
    elif val.islower():
        lower += 1
    elif val.isdigit():
        digit += 1
    else:
        symbol += 1
        
#Printing output
print("Uppercase: ", upper)
print("Lowercase: ", lower)
print("Digits: ", digit)
print("Special characters: ", symbol)
				
			

Output :

				
					Uppercase:  2
Lowercase:  9
Digits:  0
Special characters:  2
				
			

remove all characters except the given character in a string. 

count a number of non-empty substrings of a given string.