python在同一行输入2个数_Python中的子串计数和从一行输入中添加2个数字

我正在跟随一个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()方法,它的工作原理,我只是认为这不是考虑到分级人员的想法。

任何有识之士将不胜感激。

编辑:第二个问题解决了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值