Question: 2- Write a function called 'game_of_eights()' that accepts a list of numbers as an argument and then returns 'True' if two consecutive eights are found

2-

Write a function called 'game_of_eights()' that accepts a list of numbers as an argument and then returns 'True' if two consecutive 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.

Hint: You will need to use try-except to catch exceptions.

This is the skeleton for 2:

#game_of_eights() function goes here

def main(): a_list = input("Enter elements of list separated by commas: ").split(',') result = game_of_eights(a_list)

main()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!