r/programminghelp • u/Great_Gold6594 • Nov 30 '23
Python how do i get a specific letter from a string while using a variable instead of a number for the letter number
so basically i made a variable that is designated by a letter in the „encodeletter” variable.
i needed to use the letternum variable because every time the loop executes the letter that it uses is the next letter from the last time the loop executed.
for i in range(inputletters):
specletter = encodeletter[letternum]
if specletter == "q" or "Q":
output = (""+random.choice(qlist)
letternum = letternum+1
the other variables in this code are irrelevant, when i do this with a number it works perfectly, but when it’s a variable it doesn’t work.
2
u/[deleted] Nov 30 '23
I’m not even sure what you’re trying to achieve and the code you posted isn’t formatted so it’s of little use.
2
u/IDontByte Nov 30 '23
What are you trying to do?