Introduction to Programming using Python 1st Edition

Published by Pearson
ISBN 10: 0132747189
ISBN 13: 978-0-13274-718-9

Chapter 10 - Lists - Programming Exercises - Page 355: 10.27

Answer

code

Work Step by Step

# 10.27 (Pattern recognition: four consecutive equal numbers) Write the following function # that tests whether the list has four consecutive numbers with the same value: # def isConsecutiveFour(values): # Write a test program that prompts the user to enter a series of integers and reports # whether the series contains four consecutive numbers with the same value. def isConsecutiveFour(values): if len(values) != len(set(values)): # there are duplicates return False diff = values[0] - values[1] for i in range(len(values) - 1): if values[i] - values[i + 1] != diff: return False return True values = [int(x) for x in input("Enter numbers: ").split()] print(isConsecutiveFour(values))
Update this answer!

You can help us out by revising, improving and updating this answer.

Update this answer

After you claim an answer you’ll have 24 hours to send in a draft. An editor will review the submission and either publish your submission or provide feedback.