Oct-02-2021, 11:41 AM
(Aug-27-2021, 08:34 PM)snippsat Wrote:(Aug-27-2021, 07:42 PM)Teknohead23 Wrote: If I use a while loop, which I think I should, I get an infinite loop as it will always be trueA for loop is always the first choice in Python,here a example withenumerate
and f-string which you should use.
import os letters = input("Enter the first 3 letters : ").upper() num_start = 1 for index,item in enumerate(letters, num_start): dir_look = fr"C:\Users\user\Documents\Client Drawings\{letters}{index:03}" print(dir_look) check_for_folder = os.path.isdir(dir_look) print(check_for_folder
Output:Enter the first 3 letters : aaa C:\Users\user\Documents\Client Drawings\AAA001 False C:\Users\user\Documents\Client Drawings\AAA002 False C:\Users\user\Documents\Client Drawings\AAA003 False
I cant use enumerate as it's only going to iterate 3 times as there are 3 input letters, I tried using aaaa, and it iterates 4 times, but you get AAAA001
So for the programs purpose, it's not a viable solution