question about HW1

digamma (480 points)
2 4 5
asked Oct 26, 2021 in HW1 optional by digamma (480 points)
Guys i have a question aout homework.1.

since the int_seq should be a string , containing several sequence of integers separated by commas, the integers themselves should only have 1 digit yes?

so for example the int_seq = '12,0,153,16' is not valid?

4 Answers

Best answer
gianluca5539 (9820 points)
3 6 44
answered Oct 26, 2021 by gianluca5539 (9,820 points)
selected Oct 27, 2021 by digamma

There is no limit to the number of digits. I think you wanted all numbers to be only one digit to create a list with the numbers, using a step = 2 so that you exclude the commas. 

There is a way to make a list of all the numbers from a string, if these numbers are separated by a character. The method is split(character) and in this case character is the comma, so

list = string.split(",")

 This will return a list of STRINGS (not int!) each containing one of the numbers.

Hope this helps.

GabrielAlexandru (7760 points)
2 4 29
answered Oct 26, 2021 by GabrielAlexandru (7,760 points)
It’s definitely a valid string. The integers can be made of n digits, up to the maximum value storable in memory.

If I remember correctly in the example there are some number with more than one digit.
Luigi Pizza (6120 points)
11 20 65
answered Oct 26, 2021 by Luigi Pizza (6,120 points)
edited Oct 26, 2021 by Luigi Pizza
Yes, that is a valid string, as the professors and the test did not tell us about any restriction of the number of digits a sequence can have.

I suggest either to use a list comprehension (but we haven't studied it yet), to write a list of ints, or you can even use the map function we have studied today with prof Mancini (obviously after applying the method .split(',')) if you don't want to use a for.
Excale (490 points)
0 0 6
answered Oct 26, 2021 by Excale (490 points)

There shouldn't be a maximum for the numbers, you can see it yourself from the test strings.

It seems though (somebody correct me if I'm wrong, I haven't checked the entire file) that in the tests there are no more than 3 digits per number. See the screenshot down here.

So the sequence '12,0,153,16' is indeed valid