Discuss Scratch

Zaneki
Scratcher
1000+ posts

Adding letters to a variable?

Okay, so I'm making a program where you input a word, and it changes the word into a completely new word, based on the consonants and vowels and such. So, I've already got a piece of script that I'm pretty sure would work (I can't test it, though, because it's not complete) and I'm at the part where I need to add the new letter to the sequence.

Okay, okay. That's confusing. Let me reexplain, in the hopes of being understandable.

Basically, the program was inspired by meowflash's Meowspeak Translator project, in which you input a certain word, and it “translates” it into a new word. I aim to do more or less the same thing, except my translator will use an algorithm so that it may comprehensibly translate any word you input, rather than just a few preselected words. The way my program runs, so far, is that it reads through the entered word and looks at it character by character. If it sees a character that falls is a consonant, it will replace that letter with an “m”. If it sees a character that is a vowel, it will replace that with an “e”. To make it more complex, I'm making it so that it will remember the characters it already examined and sorted into vowels and consonants, so that when it spots a double vowel (such as the “io” in “riot”) in the inputted word, it will replace the second vowel with not an e, but an o. I'm also going to try to make it so that it replaces the last consonant in an entered word with a “w” (all of this put together would turn the word “riot” into “meow”).
Whew. Alright. I hope that wasn't as confusing to read as it was to write. :P
So, here's my issue: once the code has sorted a letter into either vowel or consonant, I want it to “add” it to a variable so that it would eventually spell a whole word.
For example:

You input the word “cat”.
The code sees that the first letter, “c”, is a consonant, so it replaces it with “m”. The new letter is added to a variable (let's call this variable “newWord”). The code then looks at the second letter and sees that it is a vowel, and replaces it with “e”. It then adds it to the variable newWord, so the value of newWord is now “me”.

How can I make a variable where letters can be added to it, but without overwriting the previous letter?

(and as a side thought (because I'm such a lousy programmer to begin with), how can I make a program that replaces the final consonant with “w”, but not the first consonant (in cases of words such as “lie”)?)


Thank you SO much to whoever can answer either of my questions. Like I said, I'm a poor coder at best, so this is really tough for me, even though it's probably a piece of cake for the rest of you. :P

Last edited by Zaneki (Aug. 28, 2013 04:24:11)


look a square
;
scimonster
Scratcher
1000+ posts

Adding letters to a variable?

I would suggest using a list, where each item is a single letter. Then, when you come up against a vowel, check if the last item is a vowel. If so, add “o”; otherwise add “e”. If you're up to a consonant, add it to the list. When you're done looping, replace the last item with “w”.

Retired Community Moderator
BTW, i run Google Chrome 41.0.2272.101 on a Linux system - Ubuntu 14.04. NEW: iPad 4th gen. w/retina.

418 I'm a teapot (original - to be read by bored computer geeks)
THE GAME (you just lost)
; THE SEMICOLON LIVES ON IN OUR SIGS
Zaneki
Scratcher
1000+ posts

Adding letters to a variable?

scimonster wrote:

I would suggest using a list, where each item is a single letter. Then, when you come up against a vowel, check if the last item is a vowel. If so, add “o”; otherwise add “e”. If you're up to a consonant, add it to the list. When you're done looping, replace the last item with “w”.
Thank you! But is there a way for me to combine all of the list items so that I can give an entire word to the user?

look a square
;
scimonster
Scratcher
1000+ posts

Adding letters to a variable?

Zaneki wrote:

scimonster wrote:

I would suggest using a list, where each item is a single letter. Then, when you come up against a vowel, check if the last item is a vowel. If so, add “o”; otherwise add “e”. If you're up to a consonant, add it to the list. When you're done looping, replace the last item with “w”.
Thank you! But is there a way for me to combine all of the list items so that I can give an entire word to the user?
Yep! The (list) reporter block will report all of the items in the list. If none are more than 1 character long, it won't have spaces either.

Retired Community Moderator
BTW, i run Google Chrome 41.0.2272.101 on a Linux system - Ubuntu 14.04. NEW: iPad 4th gen. w/retina.

418 I'm a teapot (original - to be read by bored computer geeks)
THE GAME (you just lost)
; THE SEMICOLON LIVES ON IN OUR SIGS
Zaneki
Scratcher
1000+ posts

Adding letters to a variable?

scimonster wrote:

Zaneki wrote:

scimonster wrote:

I would suggest using a list, where each item is a single letter. Then, when you come up against a vowel, check if the last item is a vowel. If so, add “o”; otherwise add “e”. If you're up to a consonant, add it to the list. When you're done looping, replace the last item with “w”.
Thank you! But is there a way for me to combine all of the list items so that I can give an entire word to the user?
Yep! The (list) reporter block will report all of the items in the list. If none are more than 1 character long, it won't have spaces either.
Okay. Thank you so much! This helped a ton! :D

Just one last request: Could you close this topic, please?

look a square
;
scimonster
Scratcher
1000+ posts

Adding letters to a variable?

You're welcome.
BTW, for future reference, we don't see all of the topics, so you're most likely to have it closed by reporting your first post and asking.

Retired Community Moderator
BTW, i run Google Chrome 41.0.2272.101 on a Linux system - Ubuntu 14.04. NEW: iPad 4th gen. w/retina.

418 I'm a teapot (original - to be read by bored computer geeks)
THE GAME (you just lost)
; THE SEMICOLON LIVES ON IN OUR SIGS

Powered by DjangoBB