In case of a number with odd digits only, we've been instructed to return "None" as a sequence.
Just to make sure, should the output line look like this eventually:
In my code, the default sequence is the empty string. Is it considered equivalent to the exercise requirement?
Thanks and nice weekend to all.
None is a special value in python which means that a certain variable doesn't contain anything. It's not a string although print it will print "None". It mostly used to declare variables without enter any value to that variable.
not really a question, just saying - I am surprised by the fact that my super efficient solution that I wrote for Q5, was only almost as efficient as the simple and recommended way to solve this ex. and not much better. I was sure that the simple solution was suppose to be inefficient but it nearly matched an efficient attempt.
I even thought that it would be a good idea to cease the iteration if a best sub sequence that is found is currently longer then the next maximum possible length sub sequence, but it made little difference.
my script works exactly as described in the assignment, tho i didn't consider one issue.
when inputting '6661888' the output will be:
Please enter a positive integer: 111666618888 The maximal length is 4 Sequence starts at 3 Sequence is 6666
although '8888' is as long as '6666'.
so will this output be enough? or should i code it to return 2 different outputs?
and of-course HOW can it be done? (even if not expected)
I don't know whether it's required or not,
but you start first from finding the longest sequence, and then look for any sequence that has the same length and add it to a list of sequences (we haven't learned lists yet, but you can find a very good tutorial in the documentation, and there's lots of videos at youtube which covers the basics of python).
In general, the issue you bring up is a very common one: we design an algorithm to find something, but there may be more than one candidate. Possible strategies may be: to collect all of them (as 'Dardas' mentioned above), to choose the first one the algorithm finds, to define additional properties to break ties (e.g. the leftmost one), and to choose arbitrarily among candidates (i.e. any one is OK).
In this question, take the last option: choose arbitrarily.
Should a number starting with zeros be considered different then the same one without zeros?
Your lines of code did not take into account such cases
Please enter a positive integer: 00345
The maximal length is 1
Sequence starts at 1
Sequence is 4
Is this a correct output?
Since the input is a "non-negative integer" (as specified in the instructions), the integer 00345 is identical to the integer 345, therefor I think the correct answer would be the one you've described.
More precisely, a number cannot have leading zeros.
00345 is not a legal number, it's just a sequence of digits.
(the only exception is the number 0…).
when i enter 00345 in my program i get an error:
Traceback (most recent call last): File "C:/Users/Dell/Desktop/hw1q5tr.py", line 20, in <module> num = int(eval(input("Please enter a positive integer: "))) File "<string>", line 1 00345 ^ SyntaxError: invalid token
does this mean an error ? shoul i change something ? beacause you said this is not a legal number, and as mentioned in the instructions we should not worry about the input validation
does the index of the string starts with a "0" from the left or with a "1" from the right?
for example, for the number 122333, is the index 1 or 4?
does the number provided to the program has to be > 0 if not
does the number 0 has one even digit or no even digits?
thanks a lot
In skeleton1.py in the pre-written code, the input is collected as:
num = int(input("Please enter a positive integer: "))
The question implies that we should send this the input 3**100000, but this will not be parsed correctly, as there is no use of the eval function.
Should the end code include eval or not? (This would mean editing the given code)
You are not allowed to change any command in the skeleton file - this may fail some automatic tests.
When we will check your code we will use an explicit integer (not an arithmetic expression like 3**100000).
To find the answer for 3**100000, simply give (copy-paste) the explicit number as input.
Could you specify what you mean by "explicit number"? I couldn't find a specific decimal representation of 3**100000 that doesn't include arithmetic expressions.
can you please explain what do you mean by (copy-paste), i don't get it
-Use the IDLE's interactive mode to print the explicit number
-Mark it (like you would mark a segment of text in Word), press Ctrl+C
-Run the script you wrote
-At the point where the program asks for input, paste (Ctrl-V) the number you got earlier.
-Press Enter :)
if I added to the submitted .py file, before the first line, this line:
just so I could run it in bash without having to add the python command prefixing it every time I want to launch it
would this confuse your automatic testers?
am i supposed to add to the input an "eval" function to calculate automaticlly the 3**100000? or i can do it for my own self checking and then delete it before i put my code's H.W at moodle?