【发布时间】:2021-03-13 01:04:46
【问题描述】:
我的程序必须仅使用 while 或 for 循环(不允许使用内置函数)来计算字符串中有多少特殊字符。
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)
【问题讨论】:
-
嘿。你能更具体一点,当你说特殊字符时你的意思是什么?不是数字或字母?
标签: python string for-loop while-loop count