Rhyming words

Hello, all:

I originally posted this in the collaboration section because I felt like it would take a lot of someone’s time to help. But by suggestion I moved it here.

My coding journey has led me to this:

instead of asking Chopin about a topic:
	let N be the number of words in the player's command;
	let LASTWORD be word number N in the player's command;
	let REDACTEDWORD be LASTWORD;
	let N be the number of characters in LASTWORD;
	replace character number 1 in LASTWORD with "";
	if character number 1 of LASTWORD matches "<aeiou>":
		say "'[bold type][REDACTEDWORD][roman type] [lastword] b[lastword]d[lastword] f[lastword] g[lastword] h[lastword] k[lastword] l[lastword] m[lastword] n[lastword] p[lastword] r[lastword] s[lastword] t[lastword] v[lastword] w[lastword] z[lastword]... [one of]'Jestem w tym miejscu tak długo, że nie pamiętam nieba.'[or]'Jeśli wkrótce nie opuszczę tego miejsca, umrę.'[or]'Proszę, nie pomożesz mi? Umieram.'[or]'Trzymaj się z daleka od mężczyzny z toporem, a wychodząc zamknij drzwi.'[purely at random]";
	otherwise:
		now character number 1 in LASTWORD is "";
		if character number 1 of LASTWORD matches "<aeiou>":
			say "'[bold type][REDACTEDWORD][roman type] [lastword] b[lastword]d[lastword] f[lastword] g[lastword] h[lastword] k[lastword] l[lastword] m[lastword] n[lastword] p[lastword] r[lastword] s[lastword] t[lastword] v[lastword] w[lastword] z[lastword]... [one of]'Jestem w tym miejscu tak długo, że nie pamiętam nieba.'[or]'Jeśli wkrótce nie opuszczę tego miejsca, umrę.'[or]'Proszę, nie pomożesz mi? Umieram.'[or]'Trzymaj się z daleka od mężczyzny z toporem, a wychodząc zamknij drzwi.'[purely at random]";

Three questions:
(1) The line "if character number 1 of LASTWORD matches ‘’ does not compile. Can someone help me with the diction of this?

(2) I’d like to have efficient code. How can I check the first few letters of a word for a vowel and replace all of them with “” more efficiently?

(3) Speaking of efficient code, I’d like to just generate a random starting letter (consonant) instead of listing a long list of consonants that is static. Hopefully this makes sense.

Thank you!

(1) By default, the only accepted preposition is “of” instead of “in”. See the Standard Rules (To decide what text is character number (N - a number) in (T - text)...).

(2) You’ve already started to look at regular expressions. See WWI 20.8 Replacements for the phrase to replace matched text.

(3) You can use a [random consonant] substitution if you set it up:

To decide which text is a random consonant:
	let T be the substituted form of "[one of]b[or]c[or]z[purely at random]"; [modify list to include all consonants or consonant groups]
	decide on T.
1 Like

The phrasing I changed to:

if character number 1 in LASTWORD is "<aeiou>":

It will compile now, and the coding word right up until the phrase above. When I type something such as:

>ask Chopin about music

I get a blank prompt (> ) as a response, which to me has always indicated that the program doesn’t know how to respond.

The complete coding of the passage:

instead of asking Chopin about a topic:
	let N be the number of words in the player's command;
	let LASTWORD be word number N in the player's command;
	let REDACTEDWORD be LASTWORD;
	let N be the number of characters in LASTWORD;
	replace character number 1 in LASTWORD with "";
	if character number 1 in LASTWORD is "<aeiou>":
		say "'[bold type][REDACTEDWORD][roman type] [lastword] b[lastword]d[lastword] f[lastword] g[lastword] h[lastword] k[lastword] l[lastword] m[lastword] n[lastword] p[lastword] r[lastword] s[lastword] t[lastword] v[lastword] w[lastword] z[lastword]... [one of]'Jestem w tym miejscu tak długo, że nie pamiętam nieba.'[or]'Jeśli wkrótce nie opuszczę tego miejsca, umrę.'[or]'Proszę, nie pomożesz mi? Umieram.'[or]'Trzymaj się z daleka od mężczyzny z toporem, a wychodząc zamknij drzwi.'[purely at random]";
	otherwise:
		replace character number 1 in LASTWORD with "";
		if character number 1 in LASTWORD is "<aeiou>":
			say "'[bold type][REDACTEDWORD][roman type] [lastword] b[lastword]d[lastword] f[lastword] g[lastword] h[lastword] k[lastword] l[lastword] m[lastword] n[lastword] p[lastword] r[lastword] s[lastword] t[lastword] v[lastword] w[lastword] z[lastword]... [one of]'Jestem w tym miejscu tak długo, że nie pamiętam nieba.'[or]'Jeśli wkrótce nie opuszczę tego miejsca, umrę.'[or]'Proszę, nie pomożesz mi? Umieram.'[or]'Trzymaj się z daleka od mężczyzny z toporem, a wychodząc zamknij drzwi.'[purely at random]";

I appreciate all the help and input.