converting individual digits to string

后端 未结 4 883
感动是毒
感动是毒 2021-01-28 11:38

I think i\'m very close but i cant seem to fix my issues. I need a function that takes a 10-digit input from user (me) and sets each letter to is numeric value.

Example:

4条回答
  •  情歌与酒
    2021-01-28 12:20

    def main(phone_number):
        digits = ["2", "3", "4", "5", "6", "7", "8", "9"]
       numeric_phone=" "
       for ch in phone_number:
           if ch.isalpha():
               if ord(ch) >= 97:
                   ch = +2 (ord(ch)-97)/3
               else:
                   ch = +2 (ord(ch)-65)/3
           numeric_phone= numeric_phone+ch
       print (numeric_phone)
    

    Use ord() to convert chars to their ASCII values and then get the right number.

提交回复
热议问题