7-42 jmu-python-找字符 (15 分)

输入一个字符串及字符,输出第一次出现该字符的位置。

输入格式:

  • 行1:输入字符串
  • 行2:输入一个字符

输出格式:

  • 找到,输出对应位置,格式index=X的, X表示查找到位置
  • 找不到,输出can't find letter XX表示查找字符

输入样例:

python
t

输出样例:

index=3

输入样例:

python
l

输出样例:

can't find letter l
s = input()
a = str(input())
b = True;
count = 0
for e in s:
    count = count + 1
    if e == a:
        print("index=%d" % count)
        b = False
        break
if b == True:
    print("can't find letter {}".format(a))

  

猜你喜欢

转载自www.cnblogs.com/aimilu/p/11819149.html