Print all numbers except certain numbers.

In this program, we will print all the numbers except certain numbers.

Steps to solve the program
  1. Use for loop to print all the numbers from 1 to 10.
  2. If the number is not equal to 3 or 6 only then print the number.
				
					for i in range(0,11):
        if i != 3 or i != 6:
            print(i,end=" ")
				
			

Output :

				
					0 1 2 4 5 7 8 9 10 
				
			

count the number of even and odd numbers from a series of numbers

program to get the Fibonacci series

Count the number of even and odd numbers

In this program, we will count the number of even and odd numbers from a series of numbers.

Steps to solve the program
  1. Take a series of numbers as input.
  2. Create two variables even and odd and assign their value equal to 0.
  3. Use for loop to iterate over each number from the series.
  4. If the number is even add 1 to the even and if the number is odd add 1 to the odd.
  5. Print the output.
				
					numbers = (1, 2, 3, 4, 5, 6, 7, 8, 9)
even = 0
odd = 0

for val in numbers:
    if val%2 == 0:
        even += 1
    else:
        odd += 1
        
print("Number of even numbers: ",even)
print("Number of odd numbers: ",odd)
				
			

Output :

				
					Number of even numbers:  4
Number of odd numbers:  5
				
			

add the word from the user to the empty string

prints all the numbers from 0 to 6 except 3 and 6

Add the word in a string

In this program, we will add the word in a string.

Steps to solve the program
  1. Take a word as input from the user.
  2. Create an empty string.
  3. Add each character from the input word to the empty string using for loop with the range function.
  4. Print the output.
				
					word = input("Enter the word: ")
str1 = ""
for i in range(len(word)):
    str1 += word[i]
    
print(str1)
				
			

Output :

				
					python
				
			

construct the following pattern

count the number of even and odd numbers from a series of numbers

Construct the following pattern.

In this program, we will construct the following star pattern.

   *
   * *
   * * *
   * * * *
   * * * * *
   * * * *
   * * *
   * *
   *

Steps to solve the program
  1. Use for loop with range function to print the first 5 rows of the pattern.
  2. Use for loop with range function but in reverse order to print the last 4 rows of the pattern.
  3. Use -1 in the range function to print the pattern in reverse order.
				
					for i in range(6):
    print(i*"*")
for i in range(4,-1,-1):
    print(i*"*")
				
			

Output :

				
					
*
**
***
****
*****
****
***
**
*
				
			

numbers which are divisible by 7 and multiple of 5

add the word from the user to the empty string

Find numbers divisible by a certain number

In this program, we will find those numbers divisible by a certain number and a multiple of another number.

Steps to solve the program
  1. Use for loop with range function to iterate over all the numbers from 1500 to 2700.
  2. Using an if statement check if the number is divisible by 7 and a multiple of 5.
  3. Print such numbers
				
					for i in range(1500,2701):
        if i%7 == 0 and i%5 == 0:
            print(i, end=" ")
				
			

Output :

				
					1505 1540 1575 1610 1645 1680 1715 1750 1785 1820 1855 1890 1925 1960 
1995 2030 2065 2100 2135 2170 2205 2240 2275 2310 2345 2380 2415 2450 
2485 2520 2555 2590 2625 2660 2695 
				
			

construct the following pattern

Get a list of mobile numbers from the string

In this program, we will take a string as input and get a list of mobile numbers from the given string.

Steps to solve the program
  1. Take a list as input.
  2. Convert the string into a list using split() and create an empty list.
  3. Use for loop to iterate over every word in the list.
  4. If the length of the word is 10 and that word contains all numbers then add that word to the empty list.
  5. Print the output.
				
					#Input string
str1 = """"We have 2233 some employee 8988858683 whos 3455 mobile numbers 
        are randomly distributed 2312245566 we want 453452 to get 4532892234 
        all the mobile numbers 9999234355  from this given string"""
List1 = str1.split(" ")
List2 = []

for val in List1:
    if len(val) == 10 and val.isnumeric():
        List2.append(val)

        
#Printing outptut
print(List2)
				
			

Output :

				
					['8988858683', '2312245566', '4532892234', '9999234355']
				
			

get all the email id’s from given string

Get all the email id’s from the given string

In this program, we will take a string as input and get all the email id’s from the given string.

Steps to solve program
  1. Take a string as input.
  2. Convert the string into a list using split() and create an empty list.
  3. Using for loop iterate over each word in the string.
  4. If the character in the word contains “@” add that word to the empty string.
  5. Print the output.
				
					#Input string
str1 = """We have some employee whos john@gmail.com email id’s are 
        randomly distributed jay@lic.com we want to get hari@facebook.com 
        all the email mery@hotmail.com id’s from this given string"""
List = str1.split(" ")
List1 = []

for char in List:
    for val in char:
        if val == "@":
            List1.append(char)
            
#Printing output
print(List1)
				
			

Output :

				
					['john@gmail.com', 'jay@lic.com', 'hari@facebook.com', 'mery@hotmail.com']
				
			

print each character on a new line

get a list of all the mobile numbers from the given string

Remove repeated characters in a string

In this program, we will take a string as input and remove repeated characters in a word of a string and replace it with a single letter.

Steps to solve the program
  1. Take a string as input.
  2. Remove the repeated characters in a string using set().
  3. Print the output.
				
					#Input string
str1 = "aabbccdd"

#Printing output
print("".join(set(str1)))
				
			

Output :

				
					cabd
				
			

swap cases of a given string

print a string 3 times