Program to Construct the pattern using for loop

In this program, we will construct the pattern using a nested for loop.

Steps to solve the program
  1. Use for loop with range function to iterate over numbers from 1-5.
  2. Initiate another for loop inside the above for loop to print the number initiated by 1st for lopp times the given in the pattern.
  3. Print the output.
				
					for i in range(1,6):
        for j in range(i):
            print(i,end=" ")
        print()
				
			

Output :

				
					1 
2 2 
3 3 3 
4 4 4 4 
5 5 5 5 5 
				
			

construct the following pattern

get the Fibonacci series between 0 to 10

Find numbers divisible by number within a range

In this program, we will find the numbers divisible by number within the given range of numbers.

Steps to solve the program
  1. Use for loop to iterate over numbers between 0-100.
  2. If a number is divisible by 5, print the number.
				
					
for i in range(1,101):
    if i%5 == 0:
        print(i,end=" ")
				
			

Output :

				
					5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 
				
			

calculate the sum of all odd numbers between 1-100

construct the following pattern

Calculate the sum of odd numbers from 1-100

In this program, we will calculate the sum of odd numbers from 1-100.

Steps to solve the program
  1. Create a variable to calculate the sum and assign its value equal to 0.
  2. Use for loop to iterate over all numbers between 1-100.
  3. If the number is odd then add it to the variable created.
  4. Print the output.
				
					total = 0

for i in range(1,101):
    if i%2 != 0:
        total += i
        
print("Sum of odd numbers: ",total)
				
			

Output :

				
					Sum of odd numbers:  2500
				
			

Calculate the electricity bill

numbers which are divisible by 5 in 0-100

Calculate the electricity bill of a consumer.

In this program, we will calculate the electricity bill of a consumer.

Steps to solve the program
  1. Take the units consumed by a user as input.
  2. Calculate the number of units consumed in each category (i.e. given in the question) using for loop.
  3. Calculate the amount for each category according to the units consumed.
  4. Calculate the total of all categories and add an additional surcharge of 17%.
  5. Print the output.
				
					x=int(input("Total units consumed= "))
b=c=d=e=0
p=q=r=s=0

for i in range(1,x+1):
    if i<51:
        p += 1        
    b = p*0.5
    if i>50 and i<151:
        q += 1        
    c = q*0.75
    if i>150 and i<251:
        r += 1        
    d = r*1.25
    if i>250:
        s += 1
    e = s*1.50
y = b+c+d+e
z = y+y*0.17
print("Total Bill: ",z)
				
			

Output :

				
					Total units consumed= 350
Total Bill:  438.75
				
			

Calculate the bill according to the distance covered

calculate the sum of all odd numbers between 1-100

Calculate the bill by distance covered.

In this program, we will calculate the bill by distance covered.

Steps to solve the program
  1. Take Km covered as input through the user.
  2. Create three variables and assign their values equal to 0.
  3. In the first variable calculate the Km covered in the first 5 Km.
  4. In the second variable calculate the Km covered for the next 20 Km.
  5. In the third variable calculate the Km covered for further distance.
  6. Use for loop to calculate it.
  7. Finally, calculate the bill according to the Km covered.
  8. Print the output.
				
					km = int(input("Enter the KM covered: "))
bill = 0
a=b=c=0
for i in range(1,km+1):
    if i<6:
        a += 1
    elif i>5 and i<26:
        b += 1
    elif i>25:
        c += 1

bill = a*5 + b*12 + c*10
print("Total bill: ", bill)
				
			

Output :

				
					Enter the KM covered: 15
Total bill:  145
				
			

get input from the user if it is a string insert it into an empty list

Calculate the electricity bill

Check the input type from the user.

In this program, we will check the input type from the user and perform actions according to it.

Steps to solve the program
  1. Take input from the user and create an empty list.
  2. If the type of input is a string then add it to the empty list using for loop.
  3. Print the output.
				
					data = input("Enter your text: ")
List = []

if type(data) == str:
    for char in data:
        List.append(char)
        
print(List)
				
			

Output :

				
					Enter your text: sqatools007
['s', 'q', 'a', 't', 'o', 'o', 'l', 's', '0', '0', '7']
				
			

get input from the user if it is a number insert it into an empty list

Calculate the bill according to the distance covered

Program to print the pyramid structure

In this program, we will print the pyramid structure.

Steps to solve the program
				
					var1 = 3
var2 = 5

for i1 in range(5):
    for j1 in range(9):

        if j1 > var1 and j1 < var2:

            print("*", end=" ")
        else:
            print(" ", end=" ")
    print("\n")

    var1 = var1 - 1
    var2 = var2 + 1
				
			

Output :

				
					        *        

      * * *       

    * * * * *     

  * * * * * * *   

* * * * * * * * * 
				
			

print the pattern A

count total numbers of even numbers between 1-100

Program to print the pattern A

In this program, we will print the pattern A. To write a program to print A pattern we will divide the code into 5 different sections.

section1 :    *  *  *
section2 : *  *  *  *  *
section3:  *  *      *  *
                  *  *      *  *
section4:  *  *  *  *  *
                  *  *  *  *  *
section5:  *  *      *  *
                  *  *       *  *

 

Steps to solve the program
  1. Initiate first for loop to print 1st line.
  2. Using “for i in range(9)”.
  3. Initiate second for loop to print 2nd line.
  4. Using “for j in range(9)”.
  5. Initiate third for loop to print 3rd and 4th line.
  6. Using “for k in range(2)”.
  7. Initiate a nested for loop in an above loop using “for l in range (9)”.
  8. Initiate fourth for loop to print 5th and 6th line.
  9. Using “for m in range(2)”.
  10. Initiate a nested for loop in an above loop using “for n in range(9)”.
  11. Initiate the fifth for loop to print the 7th and 8th lines.
  12. Using “for k in range(2)”.
  13. Initiate a nested for loop in an above loop using “for l in range(9)”.
				
					"""   
    * * *
  * * * * *
  * *   * *
  * *   * *
  * * * * *
  * * * * *
  * *   * *
  * *   * *
"""
# section1
for i in range(5):
    if i == 0 or i == 4:
        print(" ", end=" ")
    else:
        print("*", end=" ")

# section2
print()
for i in range(5):
    print("*", end=" ")

# section3
print()
for _ in range(2):
    for j in range(5):
        if j == 2:
            print(" ", end=" ")
        else:
            print("*", end=" ")
    print()

# section4
for _ in range(2):
    for i in range(5):
        print("*", end=" ")
    print()
    
# section5
for _ in range(2):
    for j in range(5):
        if j == 2:
            print(" ", end=" ")
        else:
            print("*", end=" ")
    print()

				
			

Output :

				
					_______________

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

________________

				
			

print number patterns

print the pyramid structure