1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Nat2105 [25]
3 years ago
14

O

Computers and Technology
1 answer:
BaLLatris [955]3 years ago
3 0

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

import random

<em>#import</em><em> </em><em>the</em><em> </em><em>random</em><em> </em><em>module</em><em> </em>

def rand_minus(s):

<em>#initialize</em><em> </em><em>a</em><em> </em><em>function</em><em> </em><em>named</em><em> </em><em>rand_minus</em><em> </em><em>which</em><em> </em><em>takes</em><em> </em><em>on</em><em> </em><em>one</em><em> </em><em>parmaters</em><em>,</em><em> </em><em>which </em><em>is a</em><em> </em><em>string</em><em> </em>

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

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

new =''

<em>#initialize</em><em> </em><em>an</em><em> </em><em>empty</em><em> </em><em>string</em><em> </em><em>named</em><em> </em><em>new</em><em> </em>

for alp in minus_1:

<em>#loop</em><em> </em><em>through</em><em> </em><em>the</em><em> </em><em>randomly</em><em> </em><em>selected</em><em> </em><em>alphabets</em><em> </em><em>in the</em><em> </em><em>list</em><em> </em>

new+=alp

<em>#place</em><em> </em><em>each</em><em> </em><em>alphabet</em><em> </em><em>in</em><em> </em><em>the</em><em> </em><em>empty</em><em> </em><em>string</em><em> </em><em>created</em><em> </em>

return new

<em>#return</em><em> </em><em>the</em><em> </em><em>string</em><em> </em><em>in the</em><em> </em><em>new</em><em> </em><em>variable</em><em>.</em><em> </em>

<em>#</em><em> </em><em>A</em><em> </em><em>sample</em><em> </em><em>run</em><em> </em><em>of</em><em> </em><em>the</em><em> </em><em>program</em><em> </em><em>and</em><em> </em><em>its</em><em> </em><em>output</em><em> </em><em>are</em><em> </em><em>attached</em><em> </em><em>below</em><em>.</em><em> </em>

old = 'ABEFCD'

print(rand_minus(old))

Learn more :brainly.com/question/25210352

You might be interested in
Write a program that takes a date as input and outputs the date's season. The input is a string to represent the month and an in
Ulleksa [173]

Answer:

The problem here is you are comparing month names with == , in case of strings there is a difference between comparing with == and .equals. So I have changed that code please check now

Program:

import java.util.Scanner;

public class LabProgram {

public static void main(String[] args) {

Scanner scnr = new Scanner(System.in);

String inputMonth;

int inputDay;

System.out.print("Enter month:");

inputMonth = scnr.next();

System.out.print("Enter day of month");

inputDay = scnr.nextInt();

if((inputMonth.equalsIgnoreCase("march")&&inputDay>19)||inputMonth.equalsIgnoreCase("april")||inputMonth=="may"||(inputMonth.equalsIgnoreCase("june")&&inputDay<21))

{

System.out.println("spring");

}

else if((inputMonth.equalsIgnoreCase("june")&&inputDay>20)||inputMonth.equalsIgnoreCase("july")||inputMonth=="august"||(inputMonth.equalsIgnoreCase("september")&&inputDay<22))

{

System.out.println("summer");

}

else if((inputMonth.equalsIgnoreCase("september")&&inputDay>21)||inputMonth.equalsIgnoreCase("october")||inputMonth.equalsIgnoreCase("november")||(inputMonth.equalsIgnoreCase("December")&&inputDay<21))

{

System.out.println("autumn");

}

else if((inputMonth.equalsIgnoreCase("december")&&inputDay>20)||inputMonth.equalsIgnoreCase("january")||inputMonth.equalsIgnoreCase("february")||(inputMonth.equalsIgnoreCase("march")&&inputDay<20))

{

System.out.println("winter");

}

else

{

System.out.println("invalid");

} }

}

Output:

3 0
3 years ago
When adapting graphs for slides,
mojhsa [17]
I would say don't use more than 8-9 graph lines

7 0
4 years ago
It is a group of two or more computer system connect to each other​
Sedbober [7]

network is a group of two or more computer system connected together

8 0
3 years ago
If I wanted to repeat an action such as a heading for a paper, it would be helpful to _____. create a citation create a caption
salantis [7]
Um... Copy and paste
7 0
4 years ago
Read 2 more answers
Task 3&amp;4, please <br> with the formula
Anastasy [175]
It’s 12 because 3 times 4 is twelve, hope i helped!
6 0
3 years ago
Other questions:
  • Chris wants to guarantee that the instructions within the loop are executed one time regardless of thestatus of a condition. Whi
    9·1 answer
  • What is the first thing you should do before constructing a window in the IDE?
    14·1 answer
  • Compare the specialized and statistical functions in excel
    10·1 answer
  • Which of the following is NOT a valid declaration for a character string?
    8·1 answer
  • Design a Ship class with the following members:
    13·1 answer
  • Which of the following is a trend in Internet computing? People are shifting back to using desktop computers more than mobile de
    5·2 answers
  • Which types of files are saved with the .mp3 and .zip extensions?
    12·2 answers
  • Which operating system (OS) is used to run your laptop?
    15·2 answers
  • What is the best use of network in homes
    15·2 answers
  • Why is this happening when I already uploaded files to my drive?
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!