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))

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM