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
lora16 [44]
3 years ago
9

Python program

Computers and Technology
1 answer:
Serhud [2]3 years ago
7 0

Answer:

The function in Python is as follows:

def search_file(filename,mystring):

my_dict = {}

count = 0

file = open(filename)

lines = file.readlines()

for line in lines:

 count+=1

 if mystring.lower() in line.lower():

  my_dict[count] = line.rstrip('\n')

return my_dict

Explanation:

This defines the function

def search_file(filename,mystring):

This initializes an empty dictionary

my_dict = {}

This initializes the number of lines to 0

count = 0

This opens the file

file = open(filename)

This reads the lines of the file

lines = file.readlines()

This iterates through the lines

for line in lines:

This increments the number line

 count+=1

This checks if the string exists in the line

 if mystring.lower() in line.lower():

If yes, the line number and the string are added to the dictionary

  my_dict[count] = line.rstrip('\n')

This returns the dictionary

return my_dict

You might be interested in
8.10.8 guess the passcode codehs
harkovskaia [24]

Answer:

sorry its late

Explanation:

/*

* Write a program that guesses every possible 4 digit passcode

* combinations until the correct passcode is guessed.

*

* The passcode is randomly generated and stored in the variable

* secretPasscode.

*

* Print out how many guesses it took to guess the correct passcode.

*/

function start() {

   var correctCode = generateRandomPasscode();

   var b = 0;

   while(true){

       var guessCode = generateRandomPasscode();

       b++;

       if(isCorrect(guessCode, correctCode)){

           println("The correct passcode was " + guessCode);

           println("It took you " + b + " tries to guess it");

       break;

       }

   }

}

function isCorrect(guessCode, correctCode) {

   return guessCode == correctCode;

}

function generateRandomPasscode() {

   var randomPasscode = "";

   for(var i = 0; i < 4; i++) {

       var randomDigit = Randomizer.nextInt(0, 9);

       randomPasscode += randomDigit;

   }

return randomPasscode;

}

7 0
2 years ago
I will give Brainliest to the best answer, I need urgent HELP
laila [671]
The answer is B. Range
4 0
3 years ago
Given an char variable last that has been initialized to a lowercase letter, write a loop that displays all possible combination
Free_Kalibri [48]

Answer:

for (char i='a'; i<='e'; i++){

   for (char j='a'; j<='e'; j++){

       cout << i<< j<< "\n";

   }

}

Explanation:

The loop runs all characters from the inner while the outer holds one character, by doing so, a will be matched with a,b,c,... Like wise b,c,d,... and on it goes.

8 0
3 years ago
Each computer on a network requires a unique way to identify itself and to refer to other computers. This is accomplished by usi
pantera1 [17]

Answer:

True

Explanation:

<em>IP Address</em>: It is used to uniquely identify each device over the network.

3 0
3 years ago
Which type of animation is best for developing characters that would showcase depth and realism?
Roman55 [17]
3D animation is best for developing characters and would showcase depth and realism.

Conversely, one would use 2D animation to create a flat appearance.
8 0
3 years ago
Other questions:
  • Using commands you learned in lessons 1 and 2. Get your IP address, netmask, DNS hostname, and MAC address. Compare these with y
    5·1 answer
  • Discuss the important basic building blocks required to create a web page in HTML/XHTML. Discuss how to place CSS rules within y
    15·1 answer
  • You type the word "weather" when you meant to type "whether". When will Microsoft Writer or Microsoft Word flag this as a misspe
    11·2 answers
  • 2. How do web bugs invade a person’s privacy?
    10·2 answers
  • What is a help desk
    15·1 answer
  • What is an important step to take before entering your first data into your database?
    10·2 answers
  • Which two of the following skills are important for a meteorologist
    12·1 answer
  • Which of the following is false? Group of answer choices A) A string may include letters, digits, and various special characters
    7·1 answer
  • How can touch typing increase productivity of a business?
    15·2 answers
  • enter formula that uses the IF function to test whether the number of years of experience (cell M5) is greater than or equal to
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!