我正在跟随一个python网站为我的作业。它非常整洁,它给你完成和编译浏览器代码的任务。无论如何,我遇到了一个挑战,我不确定如何去做。
其中一个问题是:
The same substring may occur several times inside the same string: for example "assesses" has the substring "sses" 2 times, and
"trans-Panamanian banana" has the substring "an" 6 times. Write a
program that takes two lines of input, we call the first needle and
the second haystack. Print the number of times that needle occurs as a
substring of haystack.
我不太清楚我该如何开始这个,我知道我必须比较这两个字符串,但是如何?我使用了count方法,但它无法识别assesses中第二次出现sses。
我的第二个问题是我解决了一个问题,但我受骗了一点。
问题是:
Write a program that takes a single input line of the form «number1»+«number2», where both of these represent positive integers,
and outputs the sum of the two numbers. For example on input 5+12 the
output should be 17.
我使用了eval()方法,它的工作原理,我只是认为这不是考虑到分级人员的想法。
任何有识之士将不胜感激。
编辑:第二个问题解决了。