[Python] Write a program that takes in three lowercase characters and outputs the characters...

Discussão em 'Python' iniciado por Stack, Março 9, 2025.

  1. Stack

    Stack Membro Participativo

    Write a program that takes in three lowercase characters and outputs the characters in alphabetical order.

    Hint: Ordering three characters takes six permutations. If the input is CBA the output will be ABC.

    Write a program that takes in three lowercase characters and outputs the characters in alphabetical order.

    Hint: Ordering three characters takes six permutations.

    if the input is: c a b output is abc

    missing PERMUTATIONS! Logic errors, need six permutations, and strings. How many version of abc can we make. a = 1, b = 2, c = 3.



    #abc, cab, bca, bac, cab, cba <-- six!

    Here is my code:


    char1 = input()
    char2 = input()
    char3 = input()

    order1 = str(char1 + char2 + char3)
    order2 = str(char1 + char3 + char2)
    order3 = str(char2 + char1 + char3)
    order4 = str(char2 + char3 + char1)
    order5 = str(char3 + char2 + char1)
    order6 = str(char3 + char1 + char2)

    if order1[0] < order1[1] and order1[1] < order1[2] :
    print(char1, char3, char2)
    elif order2[0] < order2[1] and order2[1] > order2[2] :
    print(char1, char2, char3)
    elif order3[0] < order3[1] and order3[1] > order3[2] :
    print(char2, char1, char3)
    elif order4[0] < order4[1] and order4[1] > order4[2] :
    print(char2, char3, char1)
    elif order5[0] < order5[1] and order5[1] > order5[2] :
    print(char3, char1, char2)
    elif order6[0] < order6[1] and order6[1] > order6[2] :
    print(char3, char2, char1)

    I was only able to get 3/10. My other orders are not moving the characters alphabetically. I have tried changing the print order and have been unsuccessful.

    Continue reading...

Compartilhe esta Página