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

Program to print number patterns

In this program, we will print number patterns.

Steps to solve the program

We will divide this problem into 2 part
Part 1: First will print a triangle of numbers in increasing order.
1. set variable num1 = 1
2. Initiate a for loop “for i in range(5)”
3. Initiate a nested for loop “for i in range(i+1)”
the nested loop will execute with the initiate value of the outer loop
4. print variable num1, which we initiated in step 1, and increase
its value by 1 with each iteration of the nested loop.
5. print(), will change the line after each iteration of the outer loop.

Part 2: Second will print a triangle of numbers in decreasing order.

1. Initiate a for loop with a start value of 5, an end value of 0 decreases it by -1.
“for k in range(5, 0, -1)”
2. Initiate a nested for loop with start value 0 and end value k-1
“for l in range(k+1)”
the nested loop will execute with the initial value of the outer loop
3. print variable num1, which we initiated, and decrease its value by 1 with each iteration of the nested loop.
4. print(), will change the line after each iteration of the outer loop.

				
					# Part1 : First will print triangle of numbers in increasing order.
num1 = 1
for i in range(5):
    for j in range(i+1):
        print(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(num1, end=" ")
    print()
				
			

Output :

				
					1 
2 3 
4 5 6 
7 8 9 10 
11 12 13 14 15 
15 14 13 12 
11 10 9 
8 7 
6 
				
			

print the pattern T

print the pattern 

Program to print the pattern T

In this program, we will print the pattern T.

Steps to solve the program

To Solve this we will divide the problem into 2 parts.

Part 1: Print horizontal lines.

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

1. Initiate a first loop with range(3)
2. Initiate a nested loop with range(9), through this it will
print a line of *
3. Once both loops are completed two horizontal lines will print.

Part 2: Print vertical lines.

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

4. Now print 2 vertical lines in the middle with another nested loop.
5. Initiate a second loop with range(5)
6. Initiate a nested loop with range(9), through this it will print
line of * in vertical line.

				
					# This for loop section will print 2 horizontal lines.
for i in range(2):
    for j in range(9):
        print("*", end="")
    print()

# This for loop section will print vertical line of T pattern.
for i in range(5):
    for j in range(9):
        if j> 2 and j <6:
            print("*", end="")
        else:
            print(" ", end="")
    print()
				
			

Output :

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

print the multiplication table of any number

print number patterns

Program to insert a number into an empty list

Steps to solve the program
  1. Take input through the user.
  2. Create an empty string.
  3. Use for loop to iterate over each character from the input.
  4. Check if the character is a number or not using isnumeric().
  5. If it is a number then convert it into an integer using int() and add it to the empty list.
  6. Print the output.
				
					data = "125python"
List = []

for char in data:
    if char.isnumeric():
        List.append(int(char))
        
print(List)
				
			

Output :

				
					[1, 2, 5]
				
			

count the total numbers of odd numbers between 1-100

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

Total numbers of odd numbers between 1-100

In this program, we will total numbers of odd numbers between 1-100 .

Steps to solve the program
  1. Create a count variable and assign its value equal to 0.
  2. Use for loop with the range function to iterate over values between 1-100.
  3. If a number is an odd number then add 1 to the count variable.
  4. Print the output.
				
					count = 0

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

Output :

				
					Total numbers of odd number:  50
				
			

count total numbers of even numbers between 1-100

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

Total numbers of even numbers between 1-100

In this program, we will count total numbers of even numbers between 1-100.

Steps to solve the program
  1. Create a count variable and assign its value equal to 0.
  2. Use for loop with the range function to iterate over values between 1-100.
  3. If a number is an even number then add 1 to the count variable.
  4. Print the output.
				
					count = 0

for i in range(1,101):
    if i%2 == 0:
        count += 1
        
print("Total numbers of even number: ",count)
				
			

Output :

				
					Total numbers of even number:  50
				
			

print the pyramid structure

count the total numbers of odd numbers between 1-100