0
Beginner python question.
Hi I hope someone can help or at least point me in the right direction. I need to write a program to display a word with alternate letters replaced by hyphens. e.g. if the word was camel, it would show as -a-e- .I know I need to use modulus but I'm just at a complete loss...thanks in advance.
4 odpowiedzi
+ 9
You can actually do it in one line, too:
https://code.sololearn.com/c9gbfa4E8W0s/?ref=app
+ 3
This works and it use the modulus like you said. FYI, the statement I used that says, if i % 2 == 0: this is what I'm using to find the even indexes in the word. Learn how the modulus operator works if you still don't understand.
https://code.sololearn.com/cWnf6so0Ckz3/?ref=app
+ 2
word=input()
even=True
for i in word:
if even:
print("-",end='')
even=False
else:
print(i,end='')
even=True
It's not pretty, but it gets the job done
0
cheers guys.