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)
Before starting to discuss how to program the above code. We should about palindrome first.
Palindrome is a number, word, sequence, list , arry and other which reads same from backward and forward.
Palindrome Number: 121, 1111, 999, 58085
Palindrome Word: Madam, My Gym, Radar, wow.
Palindrome List: [1,2,3,2,1]
In this blogpost we are going to discuss the largest palindrome made from the product of two 3-digit numbers.
a = 100 # smallest 3 digit number
b = 999 #largest 3 digit number
palin = [] #list to keep palindrome number
for i in range(a, b+1):
for j in range(a, b+1):
num = str(i*j)
length = len(num)
count = 0
if length%2 == 0:
for inner in range(0, int(length/2)):
if num[inner] == num[len(num) - 1 - inner]:
count = count + 1
if count == length/2:
palin.append(int(num))
else:
length = length - 1
for inner in range(0, int(length/2)):
if num[inner] == num[len(num) - 1 - inner]:
count = count + 1
if count == int(length/2):
palin.append(int(num))
palin[len(palin)-1]
You should get the desired output from this program.
Keep reading Python an hour a day to learn simple Python tricks, tips and program.
Palindrome is a number, word, sequence, list , arry and other which reads same from backward and forward.
Palindrome Number: 121, 1111, 999, 58085
Palindrome Word: Madam, My Gym, Radar, wow.
Palindrome List: [1,2,3,2,1]
In this blogpost we are going to discuss the largest palindrome made from the product of two 3-digit numbers.
a = 100 # smallest 3 digit number
b = 999 #largest 3 digit number
palin = [] #list to keep palindrome number
for i in range(a, b+1):
for j in range(a, b+1):
num = str(i*j)
length = len(num)
count = 0
if length%2 == 0:
for inner in range(0, int(length/2)):
if num[inner] == num[len(num) - 1 - inner]:
count = count + 1
if count == length/2:
palin.append(int(num))
else:
length = length - 1
for inner in range(0, int(length/2)):
if num[inner] == num[len(num) - 1 - inner]:
count = count + 1
if count == int(length/2):
palin.append(int(num))
palin[len(palin)-1]
You should get the desired output from this program.
Keep reading Python an hour a day to learn simple Python tricks, tips and program.
Comments
Post a Comment