Hi
I have started few days ago, thus I am pretty new to the language.
This is my first post and I hope that this forum and the users' experience will help me to step up my understanding!
Thank yo uvery much in advance.
I am trying to write the code for the following instructions:
1- input a phrase such as: "My pet is a tiger; wild, white and with big eyes."
2- output the following list of words (all words for which the first letter is 'below' the letter "n"):
MY
IS
A
AND
BIG
EYES
3- I tried to follow the following instructions but so far I can only manage to write the code I have put at the bottom of my post:
Split the words using a variable MYVARIABLE
loop each character in the input string
check if character is a letter
add a letter to MYVARIABLE each loop until a non-alpha char is met
if character is alpha
add character to MYVARIABLE
non-alpha detected (space, punctuation, digit,...) defines the end of a word and goes to else
else
check if MYVARIABLE is smaller than "N" alphabetically
print MYVARIABLE
set MYVARIABLE = empty string
or else
set MYVARIABLE = empty string and build the next word
When running the above I have an error at the "letterx".
Could seombody please explain me how to check the first letter and or how to write the code in a cleaner way?
Thank you.
Shiro
I have started few days ago, thus I am pretty new to the language.
This is my first post and I hope that this forum and the users' experience will help me to step up my understanding!
Thank yo uvery much in advance.
I am trying to write the code for the following instructions:
1- input a phrase such as: "My pet is a tiger; wild, white and with big eyes."
2- output the following list of words (all words for which the first letter is 'below' the letter "n"):
MY
IS
A
AND
BIG
EYES
3- I tried to follow the following instructions but so far I can only manage to write the code I have put at the bottom of my post:
Split the words using a variable MYVARIABLE
loop each character in the input string
check if character is a letter
add a letter to MYVARIABLE each loop until a non-alpha char is met
if character is alpha
add character to MYVARIABLE
non-alpha detected (space, punctuation, digit,...) defines the end of a word and goes to else
else
check if MYVARIABLE is smaller than "N" alphabetically
print MYVARIABLE
set MYVARIABLE = empty string
or else
set MYVARIABLE = empty string and build the next word
userinput = "My pet is a Tiger; wild, white and with big eyes." userinput = userinput.lower() start = 0 location = userinput.find(" ") MYVARIABLE = "" loop = 0 while location >= 0: for xyz in userinput[start:location]: if xyz.isalpha(): MYVARIABLE = MYVARIABLE + xyz else: print(MYVARIABLE) pass letterx = MYVARIABLE[0] if letterx < "n": print(MYVARIABLE) MYVARIABLE = "" else: MYVARIABLE = "" loop += 1 start = location location = userinput.find(" ",location+1)I know that I can use the split function but I would like to go with the above way to understand the logic.
When running the above I have an error at the "letterx".
Could seombody please explain me how to check the first letter and or how to write the code in a cleaner way?
Thank you.
Shiro