answer.
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
Deffense [45]
2 years ago
15

BlockPy: #35.2) Animal Splits Write a function all_cats that consumes a comma-separated string of animals and prints whether all

of the animals have "cat" in their name. For example, the string "gerbil,catfish,dog,cat" would return False, but just "cat,catfish" would return True. If the function consumes an empty string, then it returns True. Call this function on a string of animals of your choice and print the result.
Computers and Technology
1 answer:
maks197457 [2]2 years ago
6 0

Answer:

def all_cats(data):

 dataArray = data.split(',')

 if(data==""):

   return True

 for i in dataArray:

   if('cat' not in i):

     return False

 

 return True

print(all_cats("gerbil,catfish,dog,cat"))

print(all_cats("cat,catfish"))

print(all_cats(""))

Explanation:

Step 1: define de function and the parameters

def all_cats(data):

Step 2: split the data by ,

dataArray = data.split(',')

Step 3 : validate if is an empty data and return true

if(data==""):

   return True

Step 4: Loop over de array data and validate if have cat in each data if not, then return false

for i in dataArray:

   if('cat' not in i):

     return False

Step 5 if have cat in each one return true

return True

Step 6 Validate with examples

print(all_cats("gerbil,catfish,dog,cat"))

print(all_cats("cat,catfish"))

print(all_cats(""))

You might be interested in
Which of these are characteristics of a Python data type? Check all that apply.
Lorico [155]

Answer:

A Python data type is weakly typed.

A Python data type can have numeric values.

A Python data type can be shown by keys and values within brackets [ ].

A Python data type can be a string, a list, or a tuple with items that can be repeated using the asterisk ( * ).

A Python data type can be a dictionary that can be updated, changed, or removed.

Aka A B C E F

4 0
2 years ago
If the input is negative, make numItemsPointer be null. Otherwise, make numItemsPointer point to numItems and multiply the value
Brilliant_brown [7]

Answer:

The code for the given statements are described below.

Explanation:

// Place code below in line 9

if(numItems < 0)  // starting of a loop

{

numItemsPointer = NULL;

}

else  

{

numItemsPointer = &numItems;

numItems = numItems * 10;   // items multiplied by 10

}   // ending of a loop

6 0
2 years ago
You need to design a data storage scheme for Hayseed Heaven library data system. There are several hundred thousand large data r
Alekssandra [29.7K]

Answer:

Make use of hash tables

Explanation:

The appropriate thing to use for this should be a hash table.

A Hash Table can be described as a data structure which stores data in an associative manner. In a hash table, data is stored in an array format, where each data value has its own unique index value. Access of data becomes very fast if we know the index of the desired data. So we can perform Hashing on ISBN Number since its unique and based on the Hash Function w ecan store the Information record.

There is no requirement for printing the file in order - HashTables dont store the data in order of insertions, so no problems with that

It becomes a data structure in which insertion and search operations are very fast irrespective of the size of the data. So Querying books details can be fast and searching will take less time.

It can also be pointed out that it wont be too expensive for Hardware implemtation as HashTables stores data based on Hash Functions and memory consumption is also optimal which reduces memory wastages.

7 0
2 years ago
Ishaan is confused between the terms webpage and website help him in understanding the difference between both​
alexgriva [62]

Answer:

A webpage is a class website and a website is a link where you can find useful information.

Explanation:

Please follow

7 0
2 years ago
An array of ints, arr, has been declared and initialized. Write the statements needed to reverse the elements in the array. So,
Yuki888 [10]

Answer:

The sample output is below.

The code is attached.

Explanation:

Sample Output:

Original array is: 1 2 457 4 Reversed array is: 4754 2 1

Code to copy:

import java.io.*;

class Main

{

    /*Define the function revArray passing the array

      and its indices.*/

    static void revArray(int arr[], int start, int end)

    {

         /*Declare an integer variable to store the

           first index.*/

         int temp;

         //Check if array is empty.

         if (start >= end)

             return;

         //Store the first index value.

         temp = arr[start];

         //Swap the last index to first index.

         arr[start] = arr[end];

         //Store the temp value to last index.

         arr[end] = temp;

         /*Call the function recursively to swap

           rest of the values.*/

         revArray(arr, start+1, end-1);

    }  

    public static void main (String[] args)

    {

         //Declare and initialize array.

         int[] arr = {1,2,4,5,7,4};

         /*Declare an integer variable to store the

         * length of array.

         */

         int count=0;

         //Set the length of array to count.

         for(int i=0;i<arr.length;i++)

             count++;

         System.out.println("Original array is:");

         ///Print the original array.

         for(int i=0; i<count;i++)

         {

             System.out.print(arr[i]+" ");

         }  

         /*Call the function to reverse the values in

         * the array itself.

         */

         revArray(arr, 0, count-1);

         System.out.println("\nReversed array is:");

         ///Print the reversed array.

         for(int i=0; i<count;i++)

         {

             System.out.print(arr[i]+" ");

         }  

    }

}

5 0
2 years ago
Other questions:
  • Where is the Name Manager dialog box found?
    13·1 answer
  • Gloria needs to show in spreadsheet form the number of students in her class who speak different languages. Which type of graph
    7·1 answer
  • In a spreadsheet, the instructions for carrying out calculations are called __________. recalculations formulas templates macros
    13·1 answer
  • Suppose that a 10-mb file is stored on a disk on the same track (track 50) in consecutive sectors. the disk arm is currently sit
    13·1 answer
  • You have been tracking your exercise routine, which involves running, lifting weights, yoga, and stretching. You want to see wha
    15·2 answers
  • Identify the normalized form of the mantissa in 111.01.
    14·1 answer
  • Item = "quesadilla"
    7·1 answer
  • Your friend Margo is considering what type of display to purchase with her new desktop computer and she asks you for advice. You
    14·1 answer
  • Design a program that asks the user for a series of names (in no particular order). After the final person’s name has been enter
    5·1 answer
  • (Package Inheritance Hierarchy) Package-delivery services, such as FedEx®, DHL® and UPS®, offer a number of different shipping o
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!