140k views
4 votes
Write a program that makes a copy of a string with all occurences of the letter 't' converted to uppercase.

Write in Python.


6

User RKI
by
8.2k points

2 Answers

6 votes

Answer:

Here's a Python program that makes a copy of a string with all occurrences of the letter 't' converted to uppercase:

Step-by-step explanation:

string = "this is a test string"

new_string = ""

for char in string:

if char == "t":

new_string += char.upper()

else:

new_string += char

print(new_string)

Aɳʂɯҽɾҽԃ Ⴆყ ɠσԃKEY ꦿ

User Hamidreza Sadegh
by
8.1k points
3 votes

Answer:

Here's a Python program that creates a copy of a given string with all occurrences of the letter 't' converted to uppercase:

def uppercase_t(string):

new_string = ""

for char in string:

if char == "t":

new_string += char.upper()

else:

new_string += char

return new_string

The function uppercase_t() accepts a string as input and creates a new string called new_string. It then loops through each character in the input string using a for loop. If the current character is the letter 't', the function converts it to uppercase using the upper() method and adds it to the new_string. Otherwise, it just adds the current character as is. Finally, the function returns the new_string.

Here's an example usage of the function:

>>> uppercase_t("test string")

'TesT sTring'

>>> uppercase_t("the quick brown fox jumps over the lazy dog")

'The quick brown fox jumps over The lazy dog'

User Sean Bollin
by
7.3k points