O
(c) Write a code segment to change the name of the Thing object something such that the new name consists of the old name with one character removed at random. For example, if
something has name "ABCD", its new name could be set to "ACD
Write the code segment below

Respuesta :

fichoh

The program written in python 3 which randomly removes one alphabet from a string and returns the new string is written thus:

import random

#import the random module

def rand_minus(s):

#initialize a function named rand_minus which takes on one parmaters, which is a string

minus_1 = random.sample(s, len(s)-1)

#using the sample method in the random module, randomly select alphabets which is one lesser than the number of alphabets passed in.

new =''

#initialize an empty string named new

for alp in minus_1:

#loop through the randomly selected alphabets in the list

new+=alp

#place each alphabet in the empty string created

return new

#return the string in the new variable.

# A sample run of the program and its output are attached below.

old = 'ABEFCD'

print(rand_minus(old))

Learn more :https://brainly.com/question/25210352

Ver imagen fichoh
ACCESS MORE