用python输入一个字符串s,一个数字n和一个字符c,统计这个字符c在字符串s中第n次出现的位置
时间: 2023-04-04 14:00:31 浏览: 84
您好,可以使用以下代码实现:
```python
s = input("请输入字符串s:")
n = int(input("请输入数字n:"))
c = input("请输入字符c:")
count =
for i in range(len(s)):
if s[i] == c:
count += 1
if count == n:
print("字符c在字符串s中第{}次出现的位置为:{}".format(n, i))
break
if count < n:
print("字符c在字符串s中不足{}次出现".format(n))
```
希望对您有帮助。
相关推荐
![c](https://img-home.csdnimg.cn/images/20210720083646.png)
![java](https://img-home.csdnimg.cn/images/20210720083646.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)
![pptx](https://img-home.csdnimg.cn/images/20210720083543.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pptx](https://img-home.csdnimg.cn/images/20210720083543.png)