inp = input("Enter word")
inplen = len(inp)
text = "sandwich"
textlen = len(text)
if inplen >= textlen:
if inp[0] == text[0]:
print("s")
if inplen >= textlen:
if inp[1] == text[1]:
print("a")
if inplen >= textlen:
if inp[2] == text[2]:
print("n")
if inplen >= textlen:
if inp[3] == text[3]:
print("d")
if inplen >= textlen:
if inp[4] == text[4]:
print("w")
if inplen >= textlen:
if inp[5] == text[5]:
print("i")
if inplen >= textlen:
if inp[6] == text[6]:
print("c")
if inplen >= textlen:
if inp[7] == text[7]:
print("h")
전체 "샌드위치"를 입력하지 않으면 출력이 표시되지 않습니다. 내가하려는 것은 프로그램이 "sandwhich"와 일치하는 모든 정확한 문자를 인쇄해야한다는 것입니다. 따라서 "샌드위치"를 입력하면 "s" "a" "n" "d" "w" "h"를 반환하고 "sand"를 입력하면 "s" "a" "n" "d"를 반환해야합니다. 감사왜이 문자열 처리가 작동하지 않습니까?
이 실패합니다 다음은 그 예이다. – Doorknob
@Doorknob하지만 OP가 입력 한 글자 만 원하니? 교수형 집행 인처럼 캐릭터가 실제로 몇 번이나 등장 하느냐는 중요하지 않습니다. – sshashank124
@Dorkorkob, 어쩌면 나는 너를 제대로 이해하지 못했을 것이다. 무슨 뜻인지 예를 들려 주시겠습니까? 감사 – sshashank124