How do i write a program, that asks the user for two strings, and proceeds to replace all occurrences of the
second string in the first string with their uppercase versions.
Example output
enter first string: i want this item
enter second string: i
Replaced string: I want thIs Item
What have you tried? We are here to help, not to do your homework for you....
st1 = raw_input("Enter the first word: ")
st2 = raw_input("Enter the second word: ")
n = st2
print n.upper()
I can't seem to make the whole sentences read. it only outputs I
In simple words I am explaining you how to solve this problem.
1. Input first sentence from the user.
2. Input second word from the user.
3. Find the word in the sentence.
4. Replace them with uppercase word.
(Sep-24-2017, 12:19 PM)King Wrote: [ -> ]How do i write a program, that asks the user for two strings, and proceeds to replace all occurrences of the
second string in the first string with their uppercase versions.
Example output
enter first string: i want this item
enter second string: i
Replaced string: I want thIs Item
To get me understanding this, so basically you want to strings and all occurrences of string B in string A to be capitalized? So for example:
A = abc123testfoobartest123bcawhat
B = test
Result = abc123TESTfoobarTEST123bcawhat
Like that, right?
Here's a little "function pack" for you:
- stringhere.find(), this function can find substrings in strings
- String slicing with [:]
- String manipulation via lists
Go read about them and you should get an idea of what to do! Good luck!
(Sep-26-2017, 10:34 AM)Saka Wrote: [ -> ]Here's a little "function pack" for you: stringhere.find(), this function can find substrings in strings String slicing with [:] String manipulation via lists
while this would probably yield the desired result, it is definitely not among the best approaches to solve the task. just a kind remark