Program to print the keys of a dictionary

In this program, we will print the keys of a dictionary.

Steps to solve the program
  1. Take a Dictionary as input.
  2. Get the keys of the DIctionary using keys().
  3. Use for loop to iterate over keys of the Dictionary.
  4. Print the output.
				
					dict1 = {'name':'virat','sports':'cricket'}

for keys in dict1.keys():
    print(keys)
				
			

Output :

				
					name
sports
				
			

create an empty list and add odd numbers from 1-10

print the values of the keys of a dictionary

Create an empty list and add odd numbers to it.

In this program, we will create an empty list and add odd numbers to it from 1-10.

Steps to solve the program
  1. Create an empty list.
  2. Use for loop to iterate over numbers from 1-10.
  3. During iteration check whether a number is odd or not.
  4. Add those numbers to the empty list.
  5. Print the output.
				
					odd = []

for i in range(1,11):
    if i%2 != 0:
        odd.append(i)
        
print(odd)
				
			

Output :

				
					[1, 3, 5, 7, 9]
				
			

create an empty list and add even numbers from 1-10

print the keys of a dictionary

Create an empty list and add even numbers in it.

In this program, we will create an empty list and add even numbers from 1-10 to it.

Steps to solve the program
  1. Create an empty list.
  2. Use for loop to iterate over numbers from 1 to 10.
  3. During iteration check whether the number is even or not.
  4. If it is an even number then add it to the empty list.
				
					even = []

for i in range(1,11):
    if i%2 == 0:
        even.append(i)
        
print(even)
				
			

Output :

				
					[2, 4, 6, 8, 10]
				
			

print each word in a string on a new line

create an empty list and add odd numbers from 1-10

Print each word on new line from the string.

In this program, we will print each word on new line from the string.

Steps to solve the program
  1. Take a string as input.
  2. Use for loop to iterate over each character from the string.
  3. Print the character on the new line.
				
					str1 = "Sqatools"

for char in str1:
    print(char,end="\n")
				
			

Output :

				
					S
q
a
t
o
o
l
s
				
			

display numbers from a list

create an empty list and add even numbers from 1-10

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