Last active
April 21, 2020 00:20
-
-
Save roman-on/4cf338abf7d03a9570145165605e40aa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
The function accepts as a string parameter. | |
The function returns a list in which the first organ represents the number of digits in the string, | |
and the second organ represents the number of letters in the string, including spaces, points, | |
punctuation, and anything other than digits. | |
>>> print(numbers_letters_count("Python 3.6.3")) | |
[3, 9] | |
""" | |
""" | |
The function returns a list in which the first organ represents the number of digits in the string, | |
and the second organ represents the number of letters in the string, including spaces, points, | |
punctuation, and anything other than digits. | |
""" | |
def numbers_letters_count(my_str): | |
list_nums = [] # list of digits in the string | |
result = [] # final result | |
for num in my_str: | |
if num.isdigit(): # result of numbers in the string | |
list_nums.append(len(num)) # getting the digit for every number and saving to list_nums | |
sum_nums = sum(list_nums) # adding all the digits together and get the number of digits in the string | |
result.append(sum_nums) # adding the number of digits in the string to the final result | |
result.append((len(my_str)) - sum_nums) # subtract the lengs of the string from number of digits in the string and addig to the result | |
return (result) # returning the final result | |
def main(): | |
<your code here> | |
if __name__ == "__main__": | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment