Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

I need help Funtion sort a-z condition

Condition
Get input name 2 value
Get input first or last

if first print output name at meet before

if last print output name at meet after

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

example1:

input

name1 : Yudkon

name2 : Anon

choose : last

output

— Yudkon —

example2:

input

name1 : Somnamna

name2 : Somset

choose : first

output

— Somnamna —

>Solution :

Hope you got the logic from my code below, if you have any questions, please ask them 😀

name1 = input("Name 1 : ")
name2 = input("Name 2 : ")
choose = input("Select first or last : ")

if choose == "first":
    if name1 < name2: # check if name1 is in front of name2 (alphabetical)
        print(name1)
    else:
        print(name2)
else:
    if name1 > name2: # check if name1 is after name2 (alphabetical)
        print(name1)
    else:
        print(name2)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading