Print a table of a number using for loop

In this program, we will print a table of a number using for loop.

Steps to solve the program
  1. Take the number 5 as input to print its table.
  2. Create a variable and assign its value equal to 0.
  3. Use a for loop to iterate over 1-10.
  4. Multiply the given number with the loop number and store the result in the created variable.
  5. Print the result after each iteration.
				
					num = 5
a = 0
for i in range(1,11):
    a = i*num
    print(i,"*",num,"=",a)
				
			

Output :

				
					1 * 5 = 5
2 * 5 = 10
3 * 5 = 15
4 * 5 = 20
5 * 5 = 25
6 * 5 = 30
7 * 5 = 35
8 * 5 = 40
9 * 5 = 45
10 * 5 = 50
				
			

print the following pattern

first 20 natural numbers using for loop

Print the following pattern using Python

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

Steps to solve the program
  1. Print the first 5 lines of the patterns using a for loop.
  2. Multiply the number in the loop by *.
  3. Print the last 6 lines of the patterns using a for loop but in reverse order.
  4. Multiply the number in the loop by *.
				
					for i in range(6):
    print(i*"*")
for i in range(6,0,-1):
    print(i*"*")
				
			

Output :

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

check whether a string contains an integer or not

Print the table of a number

Check whether string contains an integer or not

In this program, we will check whether a string contains an integer or not.

Steps to solve the program
  1. Take input through the user.
  2. Create a variable and assign its value equal to 0.
  3. Use for loop to iterate over each character of the string.
  4. Check if the character in the string is an integer or not using isnumeric().
  5. If it is a number add it to the variable that we have created.
  6. If the value of the variable is greater than 0 then print True, else print False.
				
					a = input("Enter string: ")
count = 0

for char in a:
    if char.isnumeric():
        count += 1
        
if count > 0:
    print(True)
else:
    print(False)
				
			

Output :

				
					Enter string: Python123
True
				
			

check the validity of password

print the following pattern

Check the validity of password input by users

In this program, we will check the validity of password input by users.

Steps to solve the program
  1. Import re library.
  2. Take input through the user.
  3. Check the validity of the password by using re.search() and while loop.
  4. Test the given conditions.
  5. Print the output.
				
					import re
p = input("Input your password: ")
state = True

while True:  
    if (len(p)<5 or len(p)>15):
        break
    elif not re.search("[a-z]",p):
        break
    elif not re.search("[0-9]",p):
        break
    elif not re.search("[A-Z]",p):
        break
    elif not re.search("[$#@]",p):
        break
    elif re.search("\s",p):
        break
    else:
        print("Valid Password")
        state = False
        break

if state:
    print("Not a Valid Password")
				
			

Output :

				
					Input your password: Sqatools#1@
Valid Password
				
			

get the Fibonacci series between 0 to 10

check whether a string contains an integer or not

Get the Fibonacci series between 0 to 10

In this program, we will get the Fibonacci series between 0 to 10.

Steps to solve the program
  1. Create two variables num1, and num2 and assign their values equal to 0 and 1.
  2. Create a count variable and assign its values equal to 0.
  3. While the count variable is less than 10 print num1.
  4. Add num1 and num2 and store the result in a new variable n2.
  5. Change num1 to num2 and num2 to n2 and add 1 to the count variable.
  6. Print the output.
				
					count = 0
num1,num2 = 0,1
print("Sequence is: ",end=" ")

while count < 11:
    print(num1,end=" ")
    n2 = num1 + num2
    num1 = num2
    num2 = n2
    count += 1
				
			

Output :

				
					Sequence is:  0 1 1 2 3 5 8 13 21 34 55 
				
			

construct the following pattern

check the validity of password

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