| 12345678910111213141516171819202122232425 |
- import os
- # Clear screen
- os.system("clear") # Mac or Linux
- #os.system("cls") # Windows
- def contains(string, char):
- "Check if a string contain a single character"
- # Iterate the string, character by character
- for i in string:
- # If current character matches provided character, stop and return True
- if i == char:
- return True
- # At the end, if no match was found; return False
- return False
- userInputString = input("Input a string: ")
- userInputChar = input("Input a single char: ")
- # Call contains function and output results
- if contains(userInputString, userInputChar):
- print(userInputString, "does contain", userInputChar)
- else:
- print(userInputString, "does not contain", userInputChar)
|