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
Lesechka [4]
3 years ago
15

Write a function called 'game_of_eights()' that accepts a list of numbers as an argument and then returns 'True' if two consecut

ive eights are found in the list. For example: [2,3,8,8,9] -> True. The main() function will accept a list of numbers separated by commas from the user and send it to the game_of_eights() function. Within the game_of_eights() function, you will provide logic such that: the function returns True if consecutive eights (8) are found in the list; returns False otherwise. the function can handle the edge case where the last element of the list is an 8 without crashing. the function prints out an error message saying 'Error. Please enter only integers.' if the list is found to contain any non-numeric characters. Note that it only prints the error message in such cases, not 'True' or 'False'. Examples: Enter elements of list separated by commas: 2,3,8,8,5 True Enter elements of list separated by commas: 3,4,5,8 False Enter elements of list separated by commas: 2,3,5,8,8,u Error. Please enter only integers.
Computers and Technology
1 answer:
MrRa [10]3 years ago
7 0

Answer:

In Python:

def main():

   n = int(input("List items: "))

   mylist = []

   for i in range(n):

       listitem = input(", ")

       if listitem.isdecimal() == True:

           mylist.append(int(listitem))

       else:

           mylist.append(listitem)

   print(game_of_eights(mylist))

def game_of_eights(mylist):

   retVal = "False"

   intOnly = True

   for i in range(len(mylist)):

       if isinstance(mylist[i],int) == False:

           intOnly=False

           retVal = "Please, enter only integers"

       if(intOnly == True):

           for i in range(len(mylist)-1):

               if mylist[i] == 8 and mylist[i+1]==8:

                   retVal = "True"

                   break

   return retVal

if __name__ == "__main__":

   main()

Explanation:

The main begins here

def main():

This gets the number of list items from the user

   n = int(input("List items: "))

This declares an empty list

   mylist = []

This iterates through the number of list items

   for i in range(n):

This gets input for each list item, separated by comma

       listitem = input(", ")

Checks for string and integer input before inserting item into the list

<em>        if listitem.isdecimal() == True:</em>

<em>            mylist.append(int(listitem))</em>

<em>        else:</em>

<em>            mylist.append(listitem)</em>

This calls the game_of_eights function

   print(game_of_eights(mylist))

The game_of_eights function begins here

def game_of_eights(mylist):

This initializes the return value to false

   retVal = "False"

This initializes a boolean variable to true

   intOnly = True

This following iteration checks if the list contains integers only

   for i in range(len(mylist)):

If no, the boolean variable is set to false and the return value is set to "integer only"

<em>        if isinstance(mylist[i],int) == False:</em>

<em>            intOnly=False</em>

<em>            retVal = "Please, enter only integers"</em>

This is executed if the integer contains only integers

       if(intOnly == True):

Iterate through the list

           for i in range(len(mylist)-1):

If consecutive 8's is found, update the return variable to True

<em>                if mylist[i] == 8 and mylist[i+1]==8:</em>

<em>                    retVal = "True"</em>

<em>                    break</em>

This returns either True, False or Integer only

   return retVal

This calls the main method

if __name__ == "__main__":

   main()

You might be interested in
Difference between entropy and enthalpy is
olchik [2.2K]

Answer:

Explanation:

Enthalpy is the measure of total heat present in the thermodynamic system where the pressure is constant. Entropy is the measure of disorder in a thermodynamic system.

3 0
3 years ago
During early recording, microphones picked up sound waves and turned them into electrical signals that carved a _______ into the
Tcecarenko [31]

Answer:

Groove

Explanation:

There is not much to explain

8 0
3 years ago
Which of the following statements is true?
Lilit [14]

Answer:

Option A is the correct answer choice for the above question.

Explanation:

The computer system needs intercommunication which is done inside the processor to process the task given by the user. There are two types of model is used for intercommunication--

  1. Message passing and
  2. Shared memory

The difference between two is that message passing passes the message on two points at a single unit of time whereas shared memory simultaneous shares the multiple messages. That's why shared memory is faster than message passing.

  • Hence option A is the correct choice because it also refers to the above concept. While the other is not correct because--
  • Option B states that message passing is faster than shared memory which is wrong.  
  • Option C states that message passing is used for large data but shared memory is used for large data.
  • Option D states that shared memory is unavailable in some processor which is wrong.
3 0
3 years ago
What was the impetus for corporations to begin entertainment broadcasting on radio?
Sladkaya [172]

To help radio operators on ships stay awake was the impetus for corporations to begin entertainment broadcasting on radio.

e. to help radio operators on ships stay awake

<u>Explanation:</u>

The principal radio station ever on the planet's history was made by Reginald Fessenden on Christmas Eve in 1906 when he radiated a "Christmas show" to the bewildered teams of the boats of the United Fruit Company out in the Atlantic Ocean and the Caribbean Sea.

The main voice and music signals heard over radio waves were transmitted in December 1906 from Brant Rock, Massachusetts (only south of Boston), when Canadian experimenter Reginald Fessenden delivered about an hour of talk and music for specialized onlookers and any radio beginners who may be tuning in.

Radio turned into another type of correspondence and amusement. Between the 1920s and 1950s many radio shows were communicated, and assembling around the radio at night was a typical type of diversion.

4 0
3 years ago
Which of the following is a safe work practice to protect you from electrocution hazards?
Flura [38]
What are the answer choices?
7 0
3 years ago
Other questions:
  • Laura has identified the job she wants, the skills needed for the position, and the areas she needs to improve in order to get i
    10·1 answer
  • Suppose you wanted to run a web server or ftp server from your home. what type of ip address would you want?​
    6·1 answer
  • _________ are represented using diamonds linked withparticipant ETs
    6·1 answer
  • Which name is given to an architectural framework for delivering ip multimedia services?
    8·1 answer
  • 1.
    12·1 answer
  • What happens when you press the Enter key at the end of a line of bulleted text?
    14·2 answers
  • Which popular file format loses some of the information from the image? JPEG TIFF RAW NEF
    12·1 answer
  • Write a summary of five things that you learned about CSS. Do not copy and paste the information. Summarize each point in your o
    5·1 answer
  • Which option on the Format tab is used to modify particular portions of the chart?
    13·1 answer
  • Q2
    7·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!