Sort by

recency

|

483 Discussions

|

  • + 0 comments
    #import regex package --> iterate through input, use regex "^[789]\d{9}$" to match to input using findall --> finall returns a list, if list size is not 0 then a match has been found, and print according result
    
    import re
    
    for i in range(int(input())):
        num = input()
        x = re.findall("^[789]\d{9}$", num)
        
        if len(x) > 0:
            print("YES")
        else:
            print("NO")
    
  • + 0 comments
    nums = input()
    
    for x in range(int(nums)):
      t  =  "NO"
      num = input()
      if len(num) == 10:
        if num.isdigit():
            if int(num[0]) in [7,8,9]:
                t = "YES"
      print(t)
    
  • + 0 comments
    import re
    N= int(input())
    patron =r'^[7|8|9]\d{9}'
    for i in range (N):
        s = input()
        if (re.fullmatch(patron, s )):
            print("YES")
        else:
            print("NO")
            
    
  • + 0 comments

    Here is HackerRank Validating phone numbers in python solution - https://programmingoneonone.com/hackerrank-validating-phone-numbers-solution-in-python.html

  • + 0 comments

    here's how to do it without a branch

    import re
    
    if __name__ == '__main__':
        n = int(input())
        phone_number = [input() for i in range(n)]
        
        is_phone_valid = []
        
        valid_prefix = ['7','8','9']
        valid_note = ['NO', 'YES']
        
        for i in phone_number:
            note = i.isdigit() and i[0] in valid_prefix and len(i)==10
            is_phone_valid.append(valid_note[note])
        
        print(*is_phone_valid, sep='\n')
    

    `