Calculate the number of digits and letters

In this program, we will accept a string and calculate the number of digits and letters.

Steps to solve the program
  1. Take a word as input.
  2. Create two variables to calculate the number of digits and letters and assign their values equal to 0.
  3. Use for loop to iterate over each character from the word.
  4. Check whether the character is a letter or a digit using isaplha() and isnumeric().
  5. Add 1 to the corresponding variable according to the type of the charater.
  6. Print the output.
Solution 1
				
					word = "python1234"
digit = 0
character = 0

for ele in word:
    if ele.isalpha():
        character += 1
    elif ele.isnumeric():
        digit += 1
        
print("Digits :",digit)
print("Characters: ",character)
				
			
Output
				
					Digits : 4
Characters:  6
				
			
Solution 2
				
					inputstr = 'pythons12345'
digits = '0123456789'
letters = ''
# create small case and capital case sequence with ASCII
for i in range(1, 27):
    letters = letters + chr(65+i) + chr(97+i)

digit_count = 0
letter_count = 0
# iterate over each character with loop
for word in inputstr:
    # check if word is digit and increase digit count
    if word in digits:
        digit_count += 1
    # check if word is letters and increase letter count
    elif word in letters:
        letter_count += 1


print("Digit Count :", digit_count)
print("Letter Count :", letter_count)

				
			
Output
				
					Digits Count : 5
Letter Count : 7
				
			

converts all uppercases in the word to lowercase

print the alphabet pattern ‘O’

Convert all uppercase to lowercase in a word

In this program, we will take a word as input from the user and convert all uppercase to lowercase in a word.

Steps to solve the program
  1. Take a word as input from the user.
  2. Use for loop to iterate over each character of the word.
  3. Check whether the character is uppercase or not using isupper().
  4. If it is an uppercase character convert it to lowercase using lower().
  5. Print the output.
Solution 1 :
				
					input1 = input("Enter word: ")
result = ''
for char in input1:
    if char.isupper():
        print(char.lower(),end="")
    else:
        print(char,end="")
				
			
Output :
				
					Enter word: SQATOOLS
sqatools
				
			
Solution 2 :
				
					str1 = input("Enter input string:")
result = ""
for char in str1:
    # get character ascii value 
    char_ascii = ord(char)
    # check ascii value between 65 - 90 range
    # then character is in upper case
    if 65 <= char_ascii <= 90:
        # get character exact location
        char_position = char_ascii - 65
        # convert upper char ascii to lower case.
        # add character to the result
        result = result + chr(97+char_position)
    else:
        result = result + char

print("Result :", result)
				
			
Output
				
					Enter Input String: SQATOOLS Learning
Result : sqatools learning
				
			

Fizz-Buzz Program

accepts a string and calculates the number of digits and letters

Print Fizz Buzz for multiples of certain numbers

In this program, we will print Fizz Buzz and FizzBuzz for multiples of certain numbers.

Steps to solve the program
  1. Use for loop with the range function to iterate over all the numbers from 1 to 30.
  2. If a number is multiple of 3 and 5 then print FizzBuzz.
  3. If a number is multiple of 3 print Fizz.
  4. If a number is multiple of 5 print Buzz.
				
					#Printing output
for i in range(1,31):
    if i%3 == 0 and i%5 == 0:
        print("FizzBuzz")
    elif i%3 == 0:
        print("Fizz")
    elif i%5 == 0:
        print("Buzz")
				
			

Output :

				
					Fizz
Buzz
Fizz
Fizz
Buzz
Fizz
FizzBuzz
Fizz
Buzz
Fizz
Fizz
Buzz
Fizz
FizzBuzz
				
			

program to get the Fibonacci series

converts all uppercases in the word to lowercase

Get the Fibonacci series between 0 to 20.

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

Steps to solve the program
  1. Create two variables and assign their values equal to 0 and 1 respectively.
  2. Create another variable count and assign its value equal to 0.
  3. While the count variable is less than 20 print the num1.
  4. Add num1 and num2 and assign their addition to the n2 variable.
  5. Change the value of num1 with num2 and num2 with n2.
  6. Add 1 to the count variable.
  7. Print the Fibonacci series.
				
					num1 = 0
num2 = 1
count = 0

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

Output :

				
					0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 
				
			

prints all the numbers from 0 to 6 except 3 and 6

Fizz-Buzz program

Print all numbers except certain numbers.

In this program, we will print all the numbers except certain numbers.

Steps to solve the program
  1. Use for loop to print all the numbers from 1 to 10.
  2. If the number is not equal to 3 or 6 only then print the number.
				
					for i in range(0,11):
        if i != 3 or i != 6:
            print(i,end=" ")
				
			

Output :

				
					0 1 2 4 5 7 8 9 10 
				
			

count the number of even and odd numbers from a series of numbers

program to get the Fibonacci series

Count the number of even and odd numbers

In this program, we will count the number of even and odd numbers from a series of numbers.

Steps to solve the program
  1. Take a series of numbers as input.
  2. Create two variables even and odd and assign their value equal to 0.
  3. Use for loop to iterate over each number from the series.
  4. If the number is even add 1 to the even and if the number is odd add 1 to the odd.
  5. Print the output.
				
					numbers = (1, 2, 3, 4, 5, 6, 7, 8, 9)
even = 0
odd = 0

for val in numbers:
    if val%2 == 0:
        even += 1
    else:
        odd += 1
        
print("Number of even numbers: ",even)
print("Number of odd numbers: ",odd)
				
			

Output :

				
					Number of even numbers:  4
Number of odd numbers:  5
				
			

add the word from the user to the empty string

prints all the numbers from 0 to 6 except 3 and 6

Add the word in a string

In this program, we will add the word in a string.

Steps to solve the program
  1. Take a word as input from the user.
  2. Create an empty string.
  3. Add each character from the input word to the empty string using for loop with the range function.
  4. Print the output.
				
					word = input("Enter the word: ")
str1 = ""
for i in range(len(word)):
    str1 += word[i]
    
print(str1)
				
			

Output :

				
					python
				
			

construct the following pattern

count the number of even and odd numbers from a series of numbers

Construct the following pattern.

In this program, we will construct the following star pattern.

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

				
					# first loop iterate from 1 to 6
for i in range(1, 6):
    # inner loop iterate from 1 to value of i+1
    for j in range(1, i+1):
        # print * for each iteration of j
        print("*", end=" ")
    print()

# this is second section will iterate 
# from 5 to 1 in decreasing order
for i in range(5, 1, -1):
    for j in range(i, 1, -1):
        print("*", end=" ")
    print()
				
			

Output :

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

numbers which are divisible by 7 and multiple of 5

add the word from the user to the empty string

Find numbers divisible by a certain number

In this program, we will find those numbers divisible by a certain number and a multiple of another number.

Steps to solve the program
  1. Use for loop with range function to iterate over all the numbers from 1500 to 2700.
  2. Using an if statement check if the number is divisible by 7 and a multiple of 5.
  3. Print such numbers
				
					for i in range(1500,2701):
        if i%7 == 0 and i%5 == 0:
            print(i, end=" ")
				
			

Output :

				
					1505 1540 1575 1610 1645 1680 1715 1750 1785 1820 1855 1890 1925 1960 
1995 2030 2065 2100 2135 2170 2205 2240 2275 2310 2345 2380 2415 2450 
2485 2520 2555 2590 2625 2660 2695 
				
			

construct the following pattern

Python OS Module Programs, Exercises

Python os module helps to perform operating system related the task like creating a directory, removing a directory, get the current directory, copying files, running the command etc.

1). Write a Python Program To Get The Current Working Directory.

2). Write a Python Program To Get The Environment Variable

3). Write a Python Program To Set The Environment Variable

4). Write a Python Program To Get a List Of All Environment Variable Using os.environ.

5). Write a Python Program To Create a Directory Using os.mkdir()

6). Write a Python Program To Create 10 DirecTories With a Random Name.

7). Write a Python Program To Create 10 DirecTories On a Nested Level.

8). Write a Python Program To Remove An Empty Directory Using os.rmdir()

9). Write a Python Program To Remove a Non-empty DirecTory Using

10). Write a Python Program To Join 2 paths.

11). Write a Python Program To Check The File On a Given Path.

12). Write a Python Program To Check The Directory On The Given Path

13). Write a Python Program To Get a list Of all data from the Target Path.

14). Write a Python Program To Get The Total File Count In The Target Path.

15). Write a Python Program To Get The Total Folder Count In The Target Path

16). Write a Python Program To Get The Count Of Each File Extension In The Target Path.

17). Write a Python Program To Copy The File Source Path To The Target Path.

18). Write a Python Program To Copy Specific Extension Files From The Source To The Target Path.

19). Write a Python Program To Copy 10 Files In 10 Different Nested Directories.

20). Write a Python Program To Remove The File From The Given Path.

21). Write a Python Program To remove Specific Extension Files From The Target Path.

22). Write a Python Program To Create a Backup Application.
Note: We have To filter each extension file and copy it To a specific folder.

23). Write a Python Program To Run The Windows Commands.

24). Write a Python Program To Provide Command Line Arguments.

25). Write a Python Program To Get System Version Information.

26). Write a Python Program To List Path Set Using os.get_exce_path() Method.

27). Write a Python Program To Get a Random String Using os.urandom() Method.

28). Write a Python Program To Check Read Permission On Give Path Using os.access() Method.

29). Write a python Program To Get The File Size Using os.path.getsize() Method.

30). Write a Python Program To Change The Current Working Directory.

31). Write a Python Program To Scan Target DirecTory And Print All Files Name.
Using an os.scandir() Method.

32). Write a Python Program To Create Complete Path Directories With os.mkdirs() Method.

33). Write a Python Program To Execute Any Other Python Script Using os.sysetem() Method.

34). Write a Python Program To Create a Fake Data File Of 10 Different Extensions.

35). Write a Python Program To Print Data Name, PATH, and Data Type From Target Path.
Example 1:
Name : TestFolder
Path : C:\TestFolder
Type : Folder

Example 2:
Name : testdata.txt
Path : C:\testdata.txt
Type : File

36). Write a Python Program To Print All Nested Level Files/Folders Using os.walk() Methd

37). Write a Python Program To Change File/Folder Permission Using os.chmod() Method.

38). Write a Python Program To Change File/Folder Ownership Using os.chown() Method.

39). Write a Python Program To Rename Folder Name Using os.rename() Method.

40). Write a Python Program To Rename All Folders in Path Using os.remanes() Method.

41). Write a Python Program To Change Root Directory Using os.chroot() Method.

42). Write a Python Program To CPU Count Using os.cpu_count() Method.

43). Write a Python Program To Split Files/Folders from Path Using os.path.split() Method.

44). Write a Python Program To Get Ctime of File/Folder Using os.path.getctime() Method.

45). Write a Python Program To Get The Modified Time of File/Folder Using os.path.getmtime() Method.

46). Write a Python Program To Check Given Path Exist Using os.path.exists() Method.

47). Write a Python Program To Check Given Path is Link Using os.path.islink() Method.

48). Write a Python Program To Check All States of The File Using os.stat() Method.

51). Write a Python To Provide Command Line Arguments To Python File.

52). Write a Python Program To Get Platform Information.

53). Write a Python Program To Get Python Version Info.