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 :

Answer:

import random

def name_change( name: list ) -> list :

   choice = random.choice( name )

   choice_index = name.index( choice )

   name.pop( choice_index )

   return name

Explanation:

The python source code above makes use of the random package to select an item from a list in the function "name_change" and the index of that item is gotten fro the list and popped from the list "name", then the name is returned.

To call the function, assign it to a variable and add a list ( must be a list ) as its argument then print the result.

fichoh

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

import random

#import the random module

def random_minus(s):

#initialize a function named random_minus which takes a string parmater

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

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

new =''

#initialize an empty string attached to a variable named new

for alphabet in one_less:

#loop through the randomly selected alphabets in the list

new+=alphabet

#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 is attached below.

old = 'HDJJDBBD'

print(random_minus(old))

Learn more :brainly.com/question/25210352

Ver imagen fichoh