Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.


+3 votes

I got question 3 correct but I was wondering if there is a cleaner way to do it my code used .join to put the characters between the letters but I couldn't figure out how to get before and after. So I made a variable extra and set it to either the dot or the dash in each conditional and then returned this...

return extra + newString + extra

Is there a cleaner way to do this?

asked in CSC201 Spring 2021 by (8 points)



that's what i did

2 Answers

+1 vote
Best answer

I used iterarion of a string and string concatenation.

for letter in word:
    newString = newString+letter+'.'

And then in the return i used an f string, and just added a dot or a dash to the beginning depending on which if statement wss true

answered by (8 points)
selected by
+1 vote

I don’t know if there is any shorter way to do this question. On my code, I create a new variable and also use for loop to add a dot or dash after each index of the string

newVariable = ‘ ‘
for index in theString:

Inside the loop, I use concatenation and add each of the new index to be inside of my new variable. At the end, in the return statement, I add another dot or dash before my new variable.

answered by (8 points)