Print the following pattern as shown in ouput.

In this Python Program, we will print the following pattern as shown using Python

Steps to solve the program
				
					char = 97
var1 = 4
var2 = 4

for i1 in range(7):
    if i1 < 4:
        var1 = var1 - 1
        var2 = var2 + 1

        for j1 in range(9):

            if j1 > var1 and j1 < var2:

                print(chr(char), end=" ")
                char += 1
            else:
                print(" ", end=" ")
        print()

        # var1 = var1 - 1
        # var2 = var2 + 1
    else:
        var1 = var1 + 1
        var2 = var2 - 1
        for k in range(9):

            if k > var1 and k < var2:

                print(chr(char), end=" ")
                char += 1
            else:
                print(" ", end=" ")
        print()

				
			

Output :

				
					_________________


        a         
      b c d       
    e f g h i     
  j k l m n o p   
    q r s t u     
      v w x       
        y  
        
_________________
				
			

Print the following pattern

Print the following pattern as shown using Python

In this program, we will print the following pattern using Python.

Steps to solve the program
				
					# Part1 : First will print triangle of numbers in increasing order.
num1 = 65
for i in range(5):
    for j in range(i+1):
        print(chr(num1), end=" ")
        num1 += 1
    print()

# Part2 : Second will print triangle of number is decreasing order.
for k in range(5, 0, -1):
    for l in range(k-1):
        num1 += 1
        print(chr(num1), end=" ")
    print()
				
			

Output :

				
					A 
B C 
D E F 
G H I J 
K L M N O 
Q R S T 
U V W 
X Y 
Z  
				
			

find the maximum number from the list

Print the following pattern

Program to find the maximum number from the list

In this program, we will find the maximum number from the list.

Steps to solve the program
  1. Take a list as input and create a variable to find the maximum number from the list and assign its value equal to 0.
  2. Use for loop to iterate over the list elements.
  3. If an element from the list is greater than the variable that we have created then change the value of the variable by that element.
  4. Print the output.
				
					list1 = [12,14,45,88,63,97,88]
max_ = 0

for i in list1:
    if i > max_:
        max_ = i
        
print("Maximum number: ",max_)
				
			

Output :

				
					Maximum number:  97
				
			

add elements from one list to another list and print It in descending order

Print the following pattern

Add elements from one list to another list

In this program, we will add elements from one list to another list and print It in descending order.

Steps to solve the program
  1. Take a list as input and create another empty list.
  2. Use for loop to iterate over all the elements of the list.
  3. During iteration add elements to the empty list.
  4. Print the list in descending order using sorted().
				
					l1 = [2,5,8,0,1,4]
l2 = []

for ele in l1:
    l2.append(ele)
    
sorted(l2,reverse = True)
				
			

Output :

				
					[8, 5, 4, 2, 1, 0]
				
			

sort a list using for loop

find the maximum number from the list

Program to sort a list using for loop in Python.

In this program, we will sort a list using for loop in Python.

Steps to solve the program
  1. Take a list as input.
  2. Use for loop with range function to iterate over list values.
  3. Use a nested for loop to iterate over a value and remaining values of the list.
  4. If the selected value is greater than any value from the list then assign that element to a variable.
  5. Change the value of the grater value by smaller value and smallervalue by greater value.
  6. Print the output.
				
					l = [6,8,2,3,1,0,5]

for i in range(len(l)):
    for j in range(i,len(l)):
        if l[i]>l[j]:
            temp=l[i]
            l[i]=l[j]
            l[j]=temp
print(l)
				
			

Output :

				
					[0, 1, 2, 3, 5, 6, 8]
				
			

find the total number of special characters in a file

add elements from one list to another list and print It in descending order

Find the total number of special characters

In this program, we will find the total number of special characters in a file.

Steps to solve the program
  1. Create a variable to count the total number of special characters and assign its value equal to 0.
  2. Open the desired file using open() in reading mode.
  3. Use for loop iterate over the data.
  4. If the character is a special character then add 1 to the variable that we have created.
  5. Use isalnum() for this purpose.
  6. Print the output.
				
					f1=open("file1.txt","r")
data=f1.read()

is_special = 0

for char in data:
    if char.isalnum():
        is_special += 1
        
print("NUmber of digits: ",is_special)
				
			

Output :

				
					3
				
			

find the total number of Uppercase letters in a file

sort a list using for loop

Program to find the total number of Uppercase letters

In this program, we will find the total number of Uppercase letters in a file.

Steps to solve the program
  1. Create a variable to count the total number of uppercase letters and assign its value equal to 0.
  2. Open the desired file using open() in reading mode.
  3. Use for loop iterate over the data.
  4. If the character is an Uppercase letter then add 1 to the variable that we have created.
  5. Use isupper() for this purpose.
  6. Print the output.
				
					f1=open("file1.txt","r")
data=f1.read()

is_upper = 0

for char in data:
    if char.isupper():
        is_upper += 1
        
print("NUmber of digits: ",is_upper)
				
			

Output :

				
					2
				
			

find the total number of digits in a file

find the total number of special characters in a file

Find the total number of digits in a file

In this program, we will count the the total number of digits in a file.

Steps to solve the program
  1. Create a variable to count the total number of digits and assign its value equal to 0.
  2. Open the desired file using open() in reading mode.
  3. Use for loop iterate over the data.
  4. If the element is a digit then add 1 to the variable that we have created.
  5. Use isdigit() for this purpose.
  6. Print the output.
				
					f1=open("file1.txt","r")
data=f1.read()

is_digit = 0

for i in data:
    if i.isdigit():
        is_digit+=1
        
print("NUmber of digits: ",is_digit)
				
			

Output :

				
					3
				
			

count the total number of characters in a file

find the total number of Uppercase letters in a file

Count the total number of characters in a file

In this program, we will count the total number of characters in a file

Steps to solve the program
  1. Create a variable to count the total number of characters and assign its value equal to 0.
  2. Open the desired file using open() in reading mode.
  3. Use for loop iterate over the data.
  4. If the element is character then add 1 to the variable that we have created.
  5. Use isalpha() for this purpose.
  6. Print the output.
				
					char=0

f=open("file2.txt","r")
f1=f.read()
for ele in f1:
    if ele.isalpha():
        char+=1
f.close()

print("Number of characters: ",char)
				
			

Output :

				
					26
				
			

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

find the total number of digits in a file

Print the numbers by breaking a loop in Python.

In this program, we will print the numbers by breaking a loop in Python.

Steps to solve the program
  1. Use for loop to iterate over numbers from 1-10.
  2. If a number is not equal to 6 print the number.
  3. If a number is equal to 6 break the loop.
				
					
for i in range(1,11):
    if i != 6:
        print(i)
    if i == 6:
        break
				
			

Output :

				
					1
2
3
4
5
				
			

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

count the total number of characters in a file