I need a program that asks the user for 3 letters then asks the user for a string, then prints out all words in the string that start with the three letters...e.g
Enter 3 letters: AMD
Enter text: Advanced Micro Devices is a brand for all microsoft desktops
word: Advanced Micro Devices
word: all microsoft desktops
it's pretty simple. I'm new and having trouble figuring out how...my code is currently...
ipt1 = raw_input("Three letters: ") ## Asks for three letters
ipt2 = raw_input("Text: ") ## Asks for text
ipt1_split = ipt1.split() ## Converts three letters to list
ipt2_split = ipt2.split() ## Converts text to list
I'm not sure if you need a list or not, anyone know how to tackle this problem? Thanks!
I'd do something like this:
In this case the number of letters is dynamic, if you want it fixed to three just set
n
to three. If you want to match case of the letters, remove thelower
calls on the raw_input and the comparison inall
.Some hints:
string.startswith()
.Try this: