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.

4th May 2018, 11:40 PM
Mark Prince
Mark Prince - avatar
4 Réponses
+ 9
You can actually do it in one line, too: https://code.sololearn.com/c9gbfa4E8W0s/?ref=app
5th May 2018, 6:25 AM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 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
5th May 2018, 2:01 AM
synorax
synorax - avatar
+ 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
5th May 2018, 12:55 AM
LordHill
LordHill - avatar
0
cheers guys.
5th May 2018, 6:57 AM
Mark Prince
Mark Prince - avatar