I am following the python website for my work. This is very neat, it gives you tasks to complete and compile code in a browser. Anyway, I came up with the challenge that I'm not quite sure how to do this.
One of the questions:
The same substring can occur several times within the same string: for example, "evaluates" has the substring "sses" 2 times and the "trans-Panamanian banana" has the substring "a" 6 times. To write a program that takes two lines of input, we call the first needle and the second haystack. Print the number of times this needle is a substring of a haystack.
I'm not too sure how to start this, I know that I need to compare two lines, but how? I used the method count, but it did not recognize the second occurrence ssesin assesses.
My second question is the one that I decided, but deceived a little.
The question was:
Write a program that takes one input line of the form "number1" + "number2", where both of them are positive integers, and prints the sum of two numbers. For example, at input 5 + 12, the output should be 17.
I used the method eval()and it worked, I just think that this is not what the grader had in mind for this.
Any understanding would be greatly appreciated.
EDIT: The second question has been resolved.
source
share