vendredi 27 août 2021

How to generate unique letters and append them to a string in python?

I am currently writing a code where the user needs to enter an input string minimum of 4 to 12 letters, must not contain any numbers and must be unique. Once all three conditions are passed, the program will generate a set of letters that will include the input string and other unique letters to form double the length of the input string. I have cleared all three conditions but am unsure how to generate unique letters and append them to the input string.

def main2():
    player_input = input("Enter target letters: ").upper() 
    if  4 <= len(player_input) < 12 \
        and len(set(player_input)) == len(player_input) \
             and player_input.isalpha():
                  print(player_input)
    
    elif not 4 <= len(player_input) < 12:
         print(f"Must be unique characters from and of length 4 to 12")
    elif len(set(player_input)) != len(player_input):
         print(f"Must be unique characters from and of length 4 to 12")
    elif not player_input.isalpha():
         print(f"Must be unique characters from and of length 4 to 12")
    else:
         print(player_input)        
main2()



Aucun commentaire:

Enregistrer un commentaire