#this program shows how to work with strings import random def printString(my_string): #this function prints string char by char #each char on separate line for i in my_string: print(i) def printString1(my_string): #this function prints string char by char #each char on separate line #this is a different solution for i in range(len(my_string)): print(my_string[i]) def randomString(size): #this function generates the string #using random numbers and conversion #to character #function returns randomly generated string my_string="" for i in range(size): num=random.randint(33, 126) letter=chr(num) my_string=my_string+letter #could be written #my_string=my_string+chr(random.randint(33,126)) return my_string def validPassword(my_string): #returns True if my_string has at least #one uppercase letter, at least one digit #and at least oen lowercase letter #otherwise returns False upper=False lower=False digit=False for i in my_string: if(i.isupper()): upper=True if(i.islower()): lower=True if(i.isdigit()): digit=True if(upper and lower and digit): return True else: return False def main(): size=random.randint(7,20) print("size is ", size) name=randomString(size) print("random ", name) print("checking random name for password validity") if(validPassword(name)): print("random password valid") else: print("random password not valid") name=input("enter user password ") print("checking user password for validity ") if(validPassword(name)): print("user password valid") else: print("user password not valid") main()