5.py 744 B

12345678910111213141516171819202122232425
  1. import os
  2. # Clear screen
  3. os.system("clear") # Mac or Linux
  4. #os.system("cls") # Windows
  5. def contains(string, char):
  6. "Check if a string contain a single character"
  7. # Iterate the string, character by character
  8. for i in string:
  9. # If current character matches provided character, stop and return True
  10. if i == char:
  11. return True
  12. # At the end, if no match was found; return False
  13. return False
  14. userInputString = input("Input a string: ")
  15. userInputChar = input("Input a single char: ")
  16. # Call contains function and output results
  17. if contains(userInputString, userInputChar):
  18. print(userInputString, "does contain", userInputChar)
  19. else:
  20. print(userInputString, "does not contain", userInputChar)