Python Program To Print Numbers Before A Number.

In this program, we will print the numbers before a number.

Steps to solve the program
  1. Create a variable and assign its value equal to 1.
  2. While the value of the variable is less than 11 print the number.
  3. Add 1 to the variable.
  4. If the value of the variable is equal to 6 break the loop.
				
					#81
count = 1

while count < 11:
    print(count)
    count += 1
    if count == 6:
        break
				
			

Output :

				
					1
2
3
4
5
				
			

print the last element of a list using a while loop

print 1-10 natural numbers but it should stop when the number is 6

The last element of list using a while loop

In this program, we will print the last element of list using a while loop.

Steps to solve the program
  1. Take a list as input, create a variable and assign its value equal to 0.
  2. While the value of the variable is less than the length of the list add 1 to the variable.
  3. At the end of the loop, the variable’s value is equal to the length of the list.
  4. Print the last element of the list with the help of that variable and indexing.
				
					list1 = ["s","q","a","t","o","o","l","s"]
count = 0

while count<len(list1):
    count += 1
    a = count

print("Last element of the list: ",list1[a-1])
				
			
				
					Last element of the list:  s
				
			

Output :

add special characters in an empty list from a given list

print 1-10 natural numbers but it should stop when the number is 6

Add special characters in an empty list

In this program, we will add special characters to an empty list.

Steps to solve the program
  1. Take a list as input.
  2. Create a list of special characters and create an empty list.
  3. Use for loop to iterate over input list.
  4. If the character from the input list is in the list of special characters then add it to the empty list.
  5. Print the output.
				
					list1 = ["s",2,4,6,"a","@","!","%","#"]
special_char = ["!","@","#","$","%","^","}"
               ,"&","*","(",")","{","[","]"]
list2 = []

for char in list1:
    if char in special_char:
        list2.append(char)
        
print(list2)
				
			

Output :

				
					['@', '!', '%', '#']
				
			

add odd numbers in an empty list from a given list

print the last element of a list using a while loop

Program to add odd numbers in an empty list

In this program, we will add odd numbers to an empty list.

Steps to solve the program
  1. Take a list as input and create an empty list.
  2. Use for loop to iterate over each number of the input list.
  3. If the number is odd then add it to the empty list.
  4. Print the output.
				
					list1 = [3,8,5,0,2,7]
odd = []

for val in list1:
    if val%2 != 0:
        odd.append(val)
        
print("Even numbers: ",odd)
				
			

Output :

				
					Even numbers:  [3, 5, 7]
				
			

add even numbers in an empty list from a given list

add special characters in an empty list from a given list 

Program to add even numbers in an empty list

In this program, we will add even numbers to an empty list.

Steps to solve the program
  1. Take a list as input and create an empty list.
  2. Use for loop to iterate over each number of the input list.
  3. If the number is even then add it to the empty list.
  4. Print the output.
				
					list1 = [2,3,5,76,9,0,16]
even = []

for val in list1:
    if val%2 == 0:
        even.append(val)
        
print("Even numbers: ",even)
				
			

Output :

				
					Even numbers:  [2, 76, 0, 16]
				
			

find the total number of special characters in a string

add odd numbers in an empty list from a given list

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

Print the days in a week except for Sunday

In this program, we will print the days in a week except for Sunday.

Steps to solve the program
  1. Take a list of days as input.
  2. Use for loop to iterate over each day in the list.
  3. If the iterated day is not Sunday then print the day.
  4. use the If statement for this purpose.
				
					days = ["Sunday","Monday","Tuesday","Wednesday","Thursday"
       ,"Friday","Saturday"]

for day in days:
    if day != "Sunday":
        print(day, end=" ")
				
			

Output :

				
					Monday Tuesday Wednesday Thursday Friday Saturday 
				
			

Print numbers from 1-10 except 5,6 using a while loop

find the total number of special characters in a string

Program to print certain numbers.

In this program, we will print certain numbers.

Steps to solve the program
  1. Use for loop to iterate over numbers from 1-10.
  2. Print all the numbers except 5 and 6.
  3. Use If statement for this purpose.
				
					
for i in range(1,11):
    if i != 6 and i != 5:
        print(i,end="\n")
				
			

Output :

				
					1
2
3
4
7
8
9
10
				
			

multiplication of the first 10 natural numbers

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

Find the multiplication of natural numbers

In this program, we will find the multiplication of natural numbers using Python.

Steps to solve the program
  1. Create a count variable and assign its value equal to 1.
  2. Create a product variable and assign its value equal to 1.
  3. While the value of the count variable is less than 11 multiply the product variable by the count variable.
  4. Add 1 to the count variable after each iteration.
  5. Print the output.
				
					count = 1
product = 1

while count<11:
    product *= count
    count += 1
    
print("Total: ",product)
				
			

Output :

				
					Total:  3628800
				
			

sum of the first 10 natural numbers using the while loop 

Print numbers from 1-10 except 5,6 using a while loop

Find the sum of natural numbers using Python

In this program, we will find the sum of natural numbers using Python.

Steps to solve the program
  1. Create a count variable and assign its value equal to 1.
  2. Create a total variable and assign its value equal to 0.
  3. While the value of the count variable is less than 11 add the count variable to the total.
  4. Add 1 to the count variable after each iteration.
  5. Print the output.
				
					count = 1
total = 0

while count<11:
    total += count
    count += 1
    
print("Total: ",total)
				
			

Output :

				
					Total:  55
				
			

Print the table of a number using a while loop

multiplication of the first 10 natural numbers