Python Forum
how to use the upper()
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to use the upper()
#1
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
Reply
#2
What have you tried? We are here to help, not to do your homework for you....
Reply
#3
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
Reply
#4
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.
Reply
#5
(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!
Reply
#6
(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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  extract lower/upper antitriangular matrix schniefen 2 1,447 Dec-09-2022, 08:57 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020