2021年3月12日星期五

Python: Count the number occurrences of a special character in a string (while and for loops only, no functions)

Help! My program has to count how many special characters are in a string using only only while or for loops (not allowed to use built-in functions) Any help would be highly appreciated

def compteMembres(s):        special_chars = 'F' or '4' or       i = 0      while i < len(s):          q = 0          if special_chars in s:              q = q + 1                           i = i + 1             return q    s = input("Enter string: ")    compteMembres(s)              
https://stackoverflow.com/questions/66609151/python-count-the-number-occurrences-of-a-special-character-in-a-string-while-a March 13, 2021 at 09:04AM

没有评论:

发表评论