Function Use: To print all the directories in a folder/sub-folder or directory import os def get_list_or_dir(local_dir): for dir_or_file in os.listdir(local_dir): if os.path.isdir(dir_or_file): path = os.path.join(local_dir, dir_or_file) print(dir_or_file, 'This is a directory') get_list_or_dir(path) else: print(dir_or_file) Path = os.getcwd() or define the path from where you need a file Function Call: get_list_or_dir(path)
We have already wrote a similar program on Prime Number: So, before explaining anything about prime number we will directly jump in program.
Programme for What is the 10001st prime number?
n = 2
a = []
while n < n+1:
sum = 0
for i in range(1, n+1):
if n%i == 0:
sum += 1
if sum == 2:
a.append(n)
if len(a) == 10001:
break
n = n + 1
This shall give us all the prime number till 10001st. Type a[len(a) - 1] into the console to get the output.
Keep reading Python an hour a day to learn simple Python tricks, tips and program.
Comments
Post a Comment