Python Forum
I need help to understand a homework
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I need help to understand a homework
#1
Photo 
Hello everyone I am Santiago Big Grin ,

I have never used python as a programming language and my teacher has sent us a new assignment Huh .

The problem is that I do not understand the example that he have given us to understand how the program works, so I do not know how to approach this new task.

If someone can explain the example that is written a little, I would appreciate it Angel .

Thank you very much in advance Heart .

P.S.: I let you the task following this message:

SEQUENCE
Consider the following sequence of integers:
• the first member is the number 1
• each further member is constructed such that we look at the previous member and describe
it in the following way:

1st member: 1
2nd member: the first member consists of one digit 1
the second member is therefore 11
3rd member: the second member consists of two digits 1
the third member is therefore 21
4th member: the third member consists of one digit 2 and one digit 1
the fourth member is therefore 1211
5th member: the fourth member consists of one digit 1, one digit 2 and two digits 1
the fifth member is therefore 111221
6th member: the fifth member consists of three digits 1, two digits 2 and one digit 1
the sixth member is therefore 312211

etc…

ASSIGNMENT
Write a program, which reads an integer N (≥ 1) and then prints the first N members of the
sequence.

EXAMPLE
Input: 10
Output:
1
11
21
1211
111221
312211
13112221
1113213211
31131211131221
13211311123113112211
Reply
#2
does this presentation help
Output:
1 1 --> 11 11 --> 21 2-1 --> 12-11 1-2-11 --> 11-12-21 111-22-1 --> 31-22-11 3-1-22-11 --> 13-11-22-21 ... and so on
e.g. the last number in my example 13112221 describes the previous 312211, which consists of one 3, one 1, two 2, two 1, i.e. 13112221
SantiagoPB likes this post
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
(Feb-16-2021, 10:36 AM)buran Wrote: does this presentation help
Output:
1 1 --> 11 11 --> 21 2-1 --> 12-11 1-2-11 --> 11-12-21 111-22-1 --> 31-22-11 3-1-22-11 --> 13-11-22-21 ... and so on
e.g. the last number in my example 13112221 describes the previous 312211, which consists of one 3, one 1, two 2, two 1, i.e. 13112221

Yes it is clear now, thank you a lot :D
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020