Write a program to check if a string has at least one letter and one number


Topic: Write a program to check if a string has at least one letter and one number

Solution

def checkString(str): 
    
    flag_l = False
    flag_n = False
      
    for i in str: 
        
        # if string has letter 
        if i.isalpha(): 
            flag_l = True
  
        # if string has number 
        if i.isdigit(): 
            flag_n = True
      
    return flag_l and flag_n 
  
  
print(checkString('helloworld')) 
print(checkString('helloworld2020'))



List all Python Programs