muhammad_nasif

Answer_1

Apr 20th, 2021
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.53 KB | None | 0 0
  1. x = input()
  2.  
  3. digitList = []
  4. counter_Digit = 0
  5. counter_aplphabet = 0
  6.  
  7. for data in x:
  8.     if data.isdigit():
  9.         digitList.append(data)
  10.         counter_Digit += 1
  11.     else:
  12.         counter_aplphabet += 1
  13.  
  14. if counter_aplphabet > 0 and counter_Digit > 0:
  15.     digitList.sort()
  16.     print(digitList)
  17.     sum = 0
  18.     for num in digitList:
  19.         sum += int(num)
  20.     print(sum)
  21. elif counter_aplphabet == 0:
  22.     print("There is no alphabet in the string")
  23. elif counter_Digit == 0:
  24.     print("There is no digit in the string")
  25.  
Advertisement
Add Comment
Please, Sign In to add comment