Issue
I have written the code below in which each after each letter there will be a |
:
def art(word):
numoflet = len(word)
word = word.upper()
for Y in range(numoflet - 1, 0, -1):
if word[Y:].count(word[Y]) >= 2:
pass
else:
let = word[Y]
let1 = let + "|"
word = word.replace(let, let1)
word = "|" + word
pat = ""
numoflet = len(word)
for X in range(numoflet, 0, -1):
if X % 2 == 0:
pat = pat + "-"
else:
pat = pat + "+"
print("\n" + pat + "\n\n" + word + "\n\n" + pat)
word = "Craig'n'Dave"
art(word)
My intended output is;
+-+-+-+-+-+-+-+-+-+-+-+-+
|C|R|A|I|G|'|N|'|D|A|V|E|
+-+-+-+-+-+-+-+-+-+-+-+-+
However after some letters (C, N, D below) it does not produce the |
shown in the result below:
-+-+-+-+-+-+-+-+-+-+-+
|CR|A|I|G|'|N'|DA|V|E|
-+-+-+-+-+-+-+-+-+-+-+
Why is this happening?
Solution
Thanks for all your suggestions; it has really helped with the troubleshooting, and the problem in general, and I managed to fix it, so it is all good.
Here is my finished code:
def art(word):
numoflet=len(word)
word=word.upper()
for Y in range(numoflet-1,-1,-1):
let=word[Y]
let1=let+"|"
word=word[:Y]+word[Y].replace(let,let1)+word[Y+1:]
print(word)
print(Y)
word="|"+word
pat=""
numoflet=len(word)
for X in range(numoflet,0,-1):
if X%2==0:
pat=pat+"-"
else:
pat=pat+"+"
print("\n"+pat+"\n\n"+word+"\n\n"+pat)
#maincode
art("Craig'n'Dave")
Answered By - CamoMP
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.