202k views
1 vote
Define a function called replace_question(message) that replace the first occurrence of a letter (a~z, and A~Z) with the question mark "?" in string message. For example, "Clemson University is the greatest university in the world!" would become "?????? ?n??e?si?? is t?e ?re?test university in the ??rl?!" IN PYTHON CODE.

User Brittny
by
7.7k points

1 Answer

3 votes

Final answer:

To replace the first occurrence of a letter in a string with a question mark in Python, define a function 'replace_question(message)' using the provided code.

Step-by-step explanation:

To define a function called replace_question(message), which replaces the first occurrence of a letter (a-z and A-Z) with a question mark '?' in the string message, you can use the following Python code:

def replace_question(message):
for char in message:
if char.isalpha():
return message.replace(char, '?', 1)
return message

For example, 'Clemson University is the greatest university in the world!' would become '?????? ?niversity is the greatest university in the world!'

User Mproffitt
by
8.2k points