34.5k views
0 votes
Write a program that reads in a line of text and outputs the line with all the digits in all integer numbers replaced with 'x'. Please enter a line of text: My userID is john17 and my 4 digit pin is 1234 which is secret My userID is john17 and my x digit pin is xxxx which is secret Notes: 1. If a digits is part of a word, then the digit is not changed to an 'x'. For example, john17 is NOT changed to johnxx. 2. You may assume that the text entered by the user will contain only letters (upper case or lower case), digits and spaces. 3. Think how to break down your implementation to functions.

User Qazimusab
by
5.9k points

1 Answer

6 votes

Answer:

import re

def secret_pin_digit( ):

user = input("Please enter a line of text: ")

search_values = re.findall( "\d", user )

for item in search_values:

if int( item ) == "NAN":

user.replace("item", "x")

print( user )

Step-by-step explanation:

The python function program above prompts the user for a string specifying the user id, username and the user pin. The digits in the string are replaced with an "x". This is used to hide the pin of a user

User Shane Delmore
by
5.4k points