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.

 

Python Functional, Programs And Excercises

A Python function is a sequence of statements that executes a specific task. A function can take arguments, which are the information passed to the function when it is called. Functions can also return values, which are the result of executing the function.

1). Python function program to add two numbers.

2). Python function program to print the input string 10 times.

3). Python function program to print a table of a given number.

4). Python function program to find the maximum of three numbers.

Input: 17, 21, -9
Output: 21

5). Python function program to find the sum of all the numbers in a list.
Input : [6,9,4,5,3]
Output: 27

6). Python function program to multiply all the numbers in a list.
Input : [-8, 6, 1, 9, 2]
Output: -864

7). Python function program to reverse a string.
Input: Python1234
Output: 4321nohtyp

8). Python function program to check whether a number is in a given range.
Input : num = 7, range = 2 to 20
Output: 7 is in the range

9). Python function program that takes a list and returns a new list with unique elements of the first list.
Input : [2, 2, 3, 1, 4, 4, 4, 4, 4, 6]
Output : [2, 3, 1, 4, 6 ]

10). Python function program that take a number as a parameter and checks whether the number is prime or not.
Input : 7
Output : True

11). Python function program to find the even numbers from a given list.
Input : [1, 2, 3, 4, 5, 6, 7, 8, 9]
Output : [2, 4, 6, 8]

12). Python function program to create and print a list where the values are squares of numbers between 1 to 10.
Input: 1 to 10
Output: 1, 4, 9, 16, 25, 36, 49, 64, 81

13). Python function program to execute a string containing Python code.

14). Python function program to access a function inside a function.

15). Python function program to find the LCM of two numbers.
Input: 12, 20
Output: 60

16). Python function program to calculate the sum of numbers from 0 to 10.
Output: 55

17). Python function program to find the HCF of two numbers.
Input: 24 , 54
Output: 6

18). Python function program to create a function with *args as parameters.
Input: 5, 6, 8, 7
Output: 125 216 512 343

19). Python function program to get the factorial of a given number.
Input: 5
Output: 120

20). Python function program to get the Fibonacci series up to the given number.
Input: 10
Output: 1 1 2 3 5 8 13 21 34

21). Python function program to check whether a combination of two numbers has a sum of 10 from the given list.
Input : [2, 5, 6, 4, 7, 3, 8, 9, 1]
Output : True

1, 22). Python function program to get unique values from the given list.
Input : [4, 6, 1, 7, 6, 1, 5]
Output : [4, 6, 1, 7, 5]

23). Python function program to get the duplicate characters from the string.
Input: Programming
Output: {‘g’,’m’,’r’}

24). Python function program to get the square of all values in the given dictionary.
Input = {‘a’: 4, ‘b’ :3, ‘c’ : 12, ‘d’: 6}
Output = {‘a’: 16, ‘b’ : 9, ‘c’: 144, ‘d’, 36}

25). Python function program to create dictionary output from the given string.
Note: Combination of the first and last character from each word should be
key and the same word will the value in the dictionary.
Input = “Python is easy to Learn”
Output = {‘Pn’: ‘Python’, ‘is’: ‘is’, ‘ey’: ‘easy’, ‘to’: ‘to’, ‘Ln’: ‘Learn’}

26). Python function program to print a list of prime numbers from 1 to 100.

27). Python function program to get a list of odd numbers from 1 to 100.

28). Python function program to print and accept login credentials.

29). Python function program to get the addition with the return statement.

30). Python function program to create a Fruitshop Management system.

31). Python function program to check whether the given year is a leap year.

32). Python function program to reverse an integer.

33). Python function program to create a library management system.

34). Python function program to add two Binary numbers.

35). Python function program to search words in a string.

36). Python function program to get the length of the last word in a string.

37). Python function program to get a valid mobile number.

38). Python function program to convert an integer to its word format.

39). Python function program to get all permutations from a string.

40). Python function program to create a function with **kwargs as parameters.

41). Python function program to create a function local and global variable.