Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python 3.4 The Look-and-say sequence. This code is what I got so far but it's not working. How can I solve this problem? def look_say(n):

Python 3.4 The Look-and-say sequence.

image text in transcribed

This code is what I got so far but it's not working. How can I solve this problem?

def look_say(n): i = 0 while i if i == 0: series = [1] else: cnt = 1 tmpseries = [] for j in range(1, len(series)): if series[j] == series[j - 1]: cnt += 1 else: tmpseries += [cnt, series[j - 1]] cnt = 1 tmpseries += [cnt, series[len(series) - 1]] series = tmpseries i += 1 result = str(series).strip('[]') return result 
Part III: The Look-and-Say Sequence (5 points) In mathematics, the look-and-say sequence is the sequence of integers beginning as follows: 1, 11, 21, 1211,111221,312211, 13112221, 1113213211, To generate a member of the sequence from the previous member, read off the digits of the previous member counting the number of digits in groups of the same digit. For example: 1 is read off as "one 1" or 11 11 is read off as "two 1s" or 21 21 is read off as "one 2, then one 1" or 1211 1211 is read off as "one 1, one 2, then two ls" or 111221 111221 is read off as "three 1s, two 2s, then one 1" or 312211 the function look-say that takes an integer giving which term of the look-and-say sequence we want, starting from 0, and returns a string containing that term. Term #0 is 1 term #1 is 11 term #2 is 21 and so on. Your function must return the correct string for any non-negative integer argument. No matter how long the numbers become, the only digits that will appear are 1, 2 and 3 Examples: Function Call Return Value look-say (3) 12 11. look-say (8) 31 13121 11 31221 look-say (12) 1321132 1321 112 1312211 231 131 12221 13111221 1221 Note that the quotation marks displayed in the return values are there to emphasize that the return values are strings. You should not add quotation marks to your return values

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Expert Performance Indexing In SQL Server

Authors: Jason Strate, Grant Fritchey

2nd Edition

1484211189, 9781484211182

More Books

Students also viewed these Databases questions