uaveiro-leci/1ano/fp/aula05/countDigits.py

15 lines
287 B
Python
Raw Normal View History

2022-10-20 21:22:14 +00:00
import re
def main():
print(countDigits("far4214faewf13")) # Tem de dar 6
def countDigits(string):
nums = r"[0-9]$"
count = 0
for char in string:
if re.match(nums, char):
count += 1
return count
if __name__ == "__main__":
main()