Skip to main content
Tweeted twitter.com/StackCodeReview/status/1369664364672937988
Formatting.
Source Link
ferada
  • 11.4k
  • 26
  • 65
def main():

    get_the_number_of_students_from_user()

    if (NUMBER_OF_STUDENTS > 0):
        get_the_list_of_names_from_user()
        get_the_list_of_marks_obtained_from_user()
        print_the_names_after_sorting()
        print_the_marks_obtained_after_sorting()
    else:
        print("The number of students should be greater than 0!\n",
              sep = "", end = "")



def get_the_number_of_students_from_user():

    global NUMBER_OF_STUDENTS

    NUMBER_OF_STUDENTS = int(input("Enter the number of students enrolled in "
                                   "this course: "))

    print("\n", sep = "", end = "")



def get_the_list_of_names_from_user():

    global LIST_OF_NAMES

    LIST_OF_NAMES = []

    for x in range(NUMBER_OF_STUDENTS):
        print("Enter the name of student no. ", x+1, ": ", sep = "", end = "")
        dummyVariable1 = input()
        LIST_OF_NAMES.append(dummyVariable1)

    print("\n", sep = "", end = "")



def get_the_list_of_marks_obtained_from_user():

    global MARKS_OBTAINED

    MARKS_OBTAINED = []

    for y in LIST_OF_NAMES:
        print("Enter the marks obtained by ", y, ": ", sep = "", end = "")
        dummyVariable2 = int(input())
        MARKS_OBTAINED.append(dummyVariable2)

    print("\n", sep = "", end = "")



def print_the_names_after_sorting():


    listOfNames = LIST_OF_NAMES                                                     # To let LIST_OF_NAMES stay
                                                                                    # constant.

    print("The name(s) of the student(s) enrolled in this course is(are) :-\n",
          sep = "", end = "")


    listOfNames.sort()

    for z in range(NUMBER_OF_STUDENTS):                                             # To print listOfNames like
        if (z+1 == NUMBER_OF_STUDENTS):                                             # a, b, c, d & e instead of like
            print(listOfNames[z], sep = "", end = " ")                              # ['a', 'b', 'c', 'd', 'e'].
        elif (z+2 == NUMBER_OF_STUDENTS):
            print(listOfNames[z], sep = "", end = " & ")
        else:
            print(listOfNames[z], sep = "", end = ", ")

    print("(in ascending alphabetical order).\n", sep = "", end = "")


    listOfNames.reverse()

    for w in range(NUMBER_OF_STUDENTS):                                             # To print listOfNames like
        if (w+1 == NUMBER_OF_STUDENTS):                                             # a, b, c, d & e instead of like
            print(listOfNames[w], sep = "", end = " ")                              # ['a', 'b', 'c', 'd', 'e'].
        elif (w+2 == NUMBER_OF_STUDENTS):
            print(listOfNames[w], sep = "", end = " & ")
        else:
            print(listOfNames[w], sep = "", end = ", ")

    print("(in descending alphabetical order).\n\n", sep = "", end = "")



def print_the_marks_obtained_after_sorting():


    marksObtained = MARKS_OBTAINED                                                  # To let MARKS_OBTAINED stay
                                                                                    # constant.

    print("The marks obtained by the student(s) enrolled in this course ",
          "is(are) :-\n", sep = "", end = "")


    marksObtained.sort()

    for u in range(NUMBER_OF_STUDENTS):                                             # To print marksObtained like
        if (u+1 == NUMBER_OF_STUDENTS):                                             # 1, 2, 3, 4 & 5 instead of like
            print(marksObtained[u], sep = "", end = " ")                            # [1, 2, 3, 4, 5].
        elif (u+2 == NUMBER_OF_STUDENTS):
            print(marksObtained[u], sep = "", end = " & ")
        else:
            print(marksObtained[u], sep = "", end = ", ")

    print("(in ascending order).\n", sep = "", end = "")


    marksObtained.reverse()

    for v in range(NUMBER_OF_STUDENTS):                                             # To print marksObtained like
        if (v+1 == NUMBER_OF_STUDENTS):                                             # 1, 2, 3, 4 & 5 instead of like
            print(marksObtained[v], sep = "", end = " ")                            # [1, 2, 3, 4, 5].
        elif (v+2 == NUMBER_OF_STUDENTS):
            print(marksObtained[v], sep = "", end = " & ")
        else:
            print(marksObtained[v], sep = "", end = ", ")

    print("(in descending order).\n", sep = "", end = "")



main()
```
def main():

    get_the_number_of_students_from_user()

    if (NUMBER_OF_STUDENTS > 0):
        get_the_list_of_names_from_user()
        get_the_list_of_marks_obtained_from_user()
        print_the_names_after_sorting()
        print_the_marks_obtained_after_sorting()
    else:
        print("The number of students should be greater than 0!\n",
              sep = "", end = "")



def get_the_number_of_students_from_user():

    global NUMBER_OF_STUDENTS

    NUMBER_OF_STUDENTS = int(input("Enter the number of students enrolled in "
                                   "this course: "))

    print("\n", sep = "", end = "")



def get_the_list_of_names_from_user():

    global LIST_OF_NAMES

    LIST_OF_NAMES = []

    for x in range(NUMBER_OF_STUDENTS):
        print("Enter the name of student no. ", x+1, ": ", sep = "", end = "")
        dummyVariable1 = input()
        LIST_OF_NAMES.append(dummyVariable1)

    print("\n", sep = "", end = "")



def get_the_list_of_marks_obtained_from_user():

    global MARKS_OBTAINED

    MARKS_OBTAINED = []

    for y in LIST_OF_NAMES:
        print("Enter the marks obtained by ", y, ": ", sep = "", end = "")
        dummyVariable2 = int(input())
        MARKS_OBTAINED.append(dummyVariable2)

    print("\n", sep = "", end = "")



def print_the_names_after_sorting():


    listOfNames = LIST_OF_NAMES                                                     # To let LIST_OF_NAMES stay
                                                                                    # constant.

    print("The name(s) of the student(s) enrolled in this course is(are) :-\n",
          sep = "", end = "")


    listOfNames.sort()

    for z in range(NUMBER_OF_STUDENTS):                                             # To print listOfNames like
        if (z+1 == NUMBER_OF_STUDENTS):                                             # a, b, c, d & e instead of like
            print(listOfNames[z], sep = "", end = " ")                              # ['a', 'b', 'c', 'd', 'e'].
        elif (z+2 == NUMBER_OF_STUDENTS):
            print(listOfNames[z], sep = "", end = " & ")
        else:
            print(listOfNames[z], sep = "", end = ", ")

    print("(in ascending alphabetical order).\n", sep = "", end = "")


    listOfNames.reverse()

    for w in range(NUMBER_OF_STUDENTS):                                             # To print listOfNames like
        if (w+1 == NUMBER_OF_STUDENTS):                                             # a, b, c, d & e instead of like
            print(listOfNames[w], sep = "", end = " ")                              # ['a', 'b', 'c', 'd', 'e'].
        elif (w+2 == NUMBER_OF_STUDENTS):
            print(listOfNames[w], sep = "", end = " & ")
        else:
            print(listOfNames[w], sep = "", end = ", ")

    print("(in descending alphabetical order).\n\n", sep = "", end = "")



def print_the_marks_obtained_after_sorting():


    marksObtained = MARKS_OBTAINED                                                  # To let MARKS_OBTAINED stay
                                                                                    # constant.

    print("The marks obtained by the student(s) enrolled in this course ",
          "is(are) :-\n", sep = "", end = "")


    marksObtained.sort()

    for u in range(NUMBER_OF_STUDENTS):                                             # To print marksObtained like
        if (u+1 == NUMBER_OF_STUDENTS):                                             # 1, 2, 3, 4 & 5 instead of like
            print(marksObtained[u], sep = "", end = " ")                            # [1, 2, 3, 4, 5].
        elif (u+2 == NUMBER_OF_STUDENTS):
            print(marksObtained[u], sep = "", end = " & ")
        else:
            print(marksObtained[u], sep = "", end = ", ")

    print("(in ascending order).\n", sep = "", end = "")


    marksObtained.reverse()

    for v in range(NUMBER_OF_STUDENTS):                                             # To print marksObtained like
        if (v+1 == NUMBER_OF_STUDENTS):                                             # 1, 2, 3, 4 & 5 instead of like
            print(marksObtained[v], sep = "", end = " ")                            # [1, 2, 3, 4, 5].
        elif (v+2 == NUMBER_OF_STUDENTS):
            print(marksObtained[v], sep = "", end = " & ")
        else:
            print(marksObtained[v], sep = "", end = ", ")

    print("(in descending order).\n", sep = "", end = "")



main()
```
def main():

    get_the_number_of_students_from_user()

    if (NUMBER_OF_STUDENTS > 0):
        get_the_list_of_names_from_user()
        get_the_list_of_marks_obtained_from_user()
        print_the_names_after_sorting()
        print_the_marks_obtained_after_sorting()
    else:
        print("The number of students should be greater than 0!\n",
              sep = "", end = "")



def get_the_number_of_students_from_user():

    global NUMBER_OF_STUDENTS

    NUMBER_OF_STUDENTS = int(input("Enter the number of students enrolled in "
                                   "this course: "))

    print("\n", sep = "", end = "")



def get_the_list_of_names_from_user():

    global LIST_OF_NAMES

    LIST_OF_NAMES = []

    for x in range(NUMBER_OF_STUDENTS):
        print("Enter the name of student no. ", x+1, ": ", sep = "", end = "")
        dummyVariable1 = input()
        LIST_OF_NAMES.append(dummyVariable1)

    print("\n", sep = "", end = "")



def get_the_list_of_marks_obtained_from_user():

    global MARKS_OBTAINED

    MARKS_OBTAINED = []

    for y in LIST_OF_NAMES:
        print("Enter the marks obtained by ", y, ": ", sep = "", end = "")
        dummyVariable2 = int(input())
        MARKS_OBTAINED.append(dummyVariable2)

    print("\n", sep = "", end = "")



def print_the_names_after_sorting():


    listOfNames = LIST_OF_NAMES                                                     # To let LIST_OF_NAMES stay
                                                                                    # constant.

    print("The name(s) of the student(s) enrolled in this course is(are) :-\n",
          sep = "", end = "")


    listOfNames.sort()

    for z in range(NUMBER_OF_STUDENTS):                                             # To print listOfNames like
        if (z+1 == NUMBER_OF_STUDENTS):                                             # a, b, c, d & e instead of like
            print(listOfNames[z], sep = "", end = " ")                              # ['a', 'b', 'c', 'd', 'e'].
        elif (z+2 == NUMBER_OF_STUDENTS):
            print(listOfNames[z], sep = "", end = " & ")
        else:
            print(listOfNames[z], sep = "", end = ", ")

    print("(in ascending alphabetical order).\n", sep = "", end = "")


    listOfNames.reverse()

    for w in range(NUMBER_OF_STUDENTS):                                             # To print listOfNames like
        if (w+1 == NUMBER_OF_STUDENTS):                                             # a, b, c, d & e instead of like
            print(listOfNames[w], sep = "", end = " ")                              # ['a', 'b', 'c', 'd', 'e'].
        elif (w+2 == NUMBER_OF_STUDENTS):
            print(listOfNames[w], sep = "", end = " & ")
        else:
            print(listOfNames[w], sep = "", end = ", ")

    print("(in descending alphabetical order).\n\n", sep = "", end = "")



def print_the_marks_obtained_after_sorting():


    marksObtained = MARKS_OBTAINED                                                  # To let MARKS_OBTAINED stay
                                                                                    # constant.

    print("The marks obtained by the student(s) enrolled in this course ",
          "is(are) :-\n", sep = "", end = "")


    marksObtained.sort()

    for u in range(NUMBER_OF_STUDENTS):                                             # To print marksObtained like
        if (u+1 == NUMBER_OF_STUDENTS):                                             # 1, 2, 3, 4 & 5 instead of like
            print(marksObtained[u], sep = "", end = " ")                            # [1, 2, 3, 4, 5].
        elif (u+2 == NUMBER_OF_STUDENTS):
            print(marksObtained[u], sep = "", end = " & ")
        else:
            print(marksObtained[u], sep = "", end = ", ")

    print("(in ascending order).\n", sep = "", end = "")


    marksObtained.reverse()

    for v in range(NUMBER_OF_STUDENTS):                                             # To print marksObtained like
        if (v+1 == NUMBER_OF_STUDENTS):                                             # 1, 2, 3, 4 & 5 instead of like
            print(marksObtained[v], sep = "", end = " ")                            # [1, 2, 3, 4, 5].
        elif (v+2 == NUMBER_OF_STUDENTS):
            print(marksObtained[v], sep = "", end = " & ")
        else:
            print(marksObtained[v], sep = "", end = ", ")

    print("(in descending order).\n", sep = "", end = "")



main()
added 2 characters in body
Source Link
def main():

    get_the_number_of_students_from_user()

    if (NUMBER_OF_STUDENTS > 0):
        get_the_list_of_names_from_user()
        get_the_list_of_marks_obtained_from_user()
        print_the_names_after_sorting()
        print_the_marks_obtained_after_sorting()
    else:
        print("The number of students should be greater than 0!\n",
              sep = "", end = "")



def get_the_number_of_students_from_user():

    global NUMBER_OF_STUDENTS

    NUMBER_OF_STUDENTS = int(input("Enter the number of students enrolled in "
                                   "this course: "))

    print("\n", sep = "", end = "")



def get_the_list_of_names_from_user():

    global LIST_OF_NAMES

    LIST_OF_NAMES = []

    for x in range(NUMBER_OF_STUDENTS):
        print("Enter the name of student no. ", x+1, ": ", sep = "", end = "")
        dummyVariable1 = input()
        LIST_OF_NAMES.append(dummyVariable1)

    print("\n", sep = "", end = "")



def get_the_list_of_marks_obtained_from_user():

    global MARKS_OBTAINED

    MARKS_OBTAINED = []

    for y in LIST_OF_NAMES:
        print("Enter the marks obtained by ", y, ": ", sep = "", end = "")
        dummyVariable2 = int(input())
        MARKS_OBTAINED.append(dummyVariable2)

    print("\n", sep = "", end = "")



def print_the_names_after_sorting():


    listOfNames = LIST_OF_NAMES                                                     # To let LIST_OF_NAMES stay
                                                                                    # constant.

    print("The name(s) of the student(s) enrolled in this course is(are) :-\n",
          sep = "", end = "")


    listOfNames.sort()

    for z in range(NUMBER_OF_STUDENTS):                                             # To print listOfNames like
        if (z+1 == NUMBER_OF_STUDENTS):                                             # a, b, c, d & e instead of like
            print(listOfNames[z], sep = "", end = " ")                              # ['a', 'b', 'c', 'd', 'e'].
        elif (z+2 == NUMBER_OF_STUDENTS):
            print(listOfNames[z], sep = "", end = " & ")
        else:
            print(listOfNames[z], sep = "", end = ", ")

    print("(in ascending alphabetical order).\n", sep = "", end = "")


    listOfNames.reverse()

    for w in range(NUMBER_OF_STUDENTS):                                             # To print listOfNames like
        if (w+1 == NUMBER_OF_STUDENTS):                                             # a, b, c, d & e instead of like
            print(listOfNames[w], sep = "", end = " ")                              # ['a', 'b', 'c', 'd', 'e'].
        elif (w+2 == NUMBER_OF_STUDENTS):
            print(listOfNames[w], sep = "", end = " & ")
        else:
            print(listOfNames[w], sep = "", end = ", ")

    print("(in descending alphabetical order).\n\n", sep = "", end = "")



def print_the_marks_obtained_after_sorting():


    marksObtained = MARKS_OBTAINED                                                  # To let MARKS_OBTAINED stay
                                                                                    # constant.

    print("The marks obtained by the student(s) enrolled in this course ",
          "is(are) :-\n", sep = "", end = "")


    marksObtained.sort()

    for u in range(NUMBER_OF_STUDENTS):                                             # To print marksObtained like
        if (u+1 == NUMBER_OF_STUDENTS):                                             # 1, 2, 3, 4 & 5 instead of like
            print(marksObtained[u], sep = "", end = " ")                            # [1, 2, 3, 4, 5].
        elif (u+2 == NUMBER_OF_STUDENTS):
            print(marksObtained[u], sep = "", end = " & ")
        else:
            print(marksObtained[u], sep = "", end = ", ")

    print("(in ascending order).\n", sep = "", end = "")


    marksObtained.reverse()

    for v in range(NUMBER_OF_STUDENTS):                                             # To print marksObtained like
        if (v+1 == NUMBER_OF_STUDENTS):                                             # 1, 2, 3, 4 & 5 instead of like
            print(marksObtained[v], sep = "", end = " ")                            # [1, 2, 3, 4, 5].
        elif (v+2 == NUMBER_OF_STUDENTS):
            print(marksObtained[v], sep = "", end = " & ")
        else:
            print(marksObtained[v], sep = "", end = ", ")

    print("(in descending order).\n", sep = "", end = "")



main()
def main():

    get_the_number_of_students_from_user()

    if (NUMBER_OF_STUDENTS > 0):
        get_the_list_of_names_from_user()
        get_the_list_of_marks_obtained_from_user()
        print_the_names_after_sorting()
        print_the_marks_obtained_after_sorting()
    else:
        print("The number of students should be greater than 0!\n",
              sep = "", end = "")



def get_the_number_of_students_from_user():

    global NUMBER_OF_STUDENTS

    NUMBER_OF_STUDENTS = int(input("Enter the number of students enrolled in "
                                   "this course: "))

    print("\n", sep = "", end = "")



def get_the_list_of_names_from_user():

    global LIST_OF_NAMES

    LIST_OF_NAMES = []

    for x in range(NUMBER_OF_STUDENTS):
        print("Enter the name of student no. ", x+1, ": ", sep = "", end = "")
        dummyVariable1 = input()
        LIST_OF_NAMES.append(dummyVariable1)

    print("\n", sep = "", end = "")



def get_the_list_of_marks_obtained_from_user():

    global MARKS_OBTAINED

    MARKS_OBTAINED = []

    for y in LIST_OF_NAMES:
        print("Enter the marks obtained by ", y, ": ", sep = "", end = "")
        dummyVariable2 = int(input())
        MARKS_OBTAINED.append(dummyVariable2)

    print("\n", sep = "", end = "")



def print_the_names_after_sorting():


    listOfNames = LIST_OF_NAMES                                                     # To let LIST_OF_NAMES stay
                                                                                    # constant.

    print("The name(s) of the student(s) enrolled in this course is(are) :-\n",
          sep = "", end = "")


    listOfNames.sort()

    for z in range(NUMBER_OF_STUDENTS):                                             # To print listOfNames like
        if (z+1 == NUMBER_OF_STUDENTS):                                             # a, b, c, d & e instead of like
            print(listOfNames[z], sep = "", end = " ")                              # ['a', 'b', 'c', 'd', 'e'].
        elif (z+2 == NUMBER_OF_STUDENTS):
            print(listOfNames[z], sep = "", end = " & ")
        else:
            print(listOfNames[z], sep = "", end = ", ")

    print("(in ascending alphabetical order).\n", sep = "", end = "")


    listOfNames.reverse()

    for w in range(NUMBER_OF_STUDENTS):                                             # To print listOfNames like
        if (w+1 == NUMBER_OF_STUDENTS):                                             # a, b, c, d & e instead of like
            print(listOfNames[w], sep = "", end = " ")                              # ['a', 'b', 'c', 'd', 'e'].
        elif (w+2 == NUMBER_OF_STUDENTS):
            print(listOfNames[w], sep = "", end = " & ")
        else:
            print(listOfNames[w], sep = "", end = ", ")

    print("(in descending alphabetical order).\n\n", sep = "", end = "")



def print_the_marks_obtained_after_sorting():


    marksObtained = MARKS_OBTAINED                                                  # To let MARKS_OBTAINED stay
                                                                                    # constant.

    print("The marks obtained by the student(s) enrolled in this course ",
          "is(are) :-\n", sep = "", end = "")


    marksObtained.sort()

    for u in range(NUMBER_OF_STUDENTS):                                             # To print marksObtained like
        if (u+1 == NUMBER_OF_STUDENTS):                                             # 1, 2, 3, 4 & 5 instead of like
            print(marksObtained[u], sep = "", end = " ")                            # [1, 2, 3, 4, 5].
        elif (u+2 == NUMBER_OF_STUDENTS):
            print(marksObtained[u], sep = "", end = " & ")
        else:
            print(marksObtained[u], sep = "", end = ", ")

    print("(in ascending order).\n", sep = "", end = "")


    marksObtained.reverse()

    for v in range(NUMBER_OF_STUDENTS):                                             # To print marksObtained like
        if (v+1 == NUMBER_OF_STUDENTS):                                             # 1, 2, 3, 4 & 5 instead of like
            print(marksObtained[v], sep = "", end = " ")                            # [1, 2, 3, 4, 5].
        elif (v+2 == NUMBER_OF_STUDENTS):
            print(marksObtained[v], sep = "", end = " & ")
        else:
            print(marksObtained[v], sep = "", end = ", ")

    print("(in descending order).\n", sep = "", end = "")



main()
```
def main():

    get_the_number_of_students_from_user()

    if (NUMBER_OF_STUDENTS > 0):
        get_the_list_of_names_from_user()
        get_the_list_of_marks_obtained_from_user()
        print_the_names_after_sorting()
        print_the_marks_obtained_after_sorting()
    else:
        print("The number of students should be greater than 0!\n",
              sep = "", end = "")



def get_the_number_of_students_from_user():

    global NUMBER_OF_STUDENTS

    NUMBER_OF_STUDENTS = int(input("Enter the number of students enrolled in "
                                   "this course: "))

    print("\n", sep = "", end = "")



def get_the_list_of_names_from_user():

    global LIST_OF_NAMES

    LIST_OF_NAMES = []

    for x in range(NUMBER_OF_STUDENTS):
        print("Enter the name of student no. ", x+1, ": ", sep = "", end = "")
        dummyVariable1 = input()
        LIST_OF_NAMES.append(dummyVariable1)

    print("\n", sep = "", end = "")



def get_the_list_of_marks_obtained_from_user():

    global MARKS_OBTAINED

    MARKS_OBTAINED = []

    for y in LIST_OF_NAMES:
        print("Enter the marks obtained by ", y, ": ", sep = "", end = "")
        dummyVariable2 = int(input())
        MARKS_OBTAINED.append(dummyVariable2)

    print("\n", sep = "", end = "")



def print_the_names_after_sorting():


    listOfNames = LIST_OF_NAMES                                                     # To let LIST_OF_NAMES stay
                                                                                    # constant.

    print("The name(s) of the student(s) enrolled in this course is(are) :-\n",
          sep = "", end = "")


    listOfNames.sort()

    for z in range(NUMBER_OF_STUDENTS):                                             # To print listOfNames like
        if (z+1 == NUMBER_OF_STUDENTS):                                             # a, b, c, d & e instead of like
            print(listOfNames[z], sep = "", end = " ")                              # ['a', 'b', 'c', 'd', 'e'].
        elif (z+2 == NUMBER_OF_STUDENTS):
            print(listOfNames[z], sep = "", end = " & ")
        else:
            print(listOfNames[z], sep = "", end = ", ")

    print("(in ascending alphabetical order).\n", sep = "", end = "")


    listOfNames.reverse()

    for w in range(NUMBER_OF_STUDENTS):                                             # To print listOfNames like
        if (w+1 == NUMBER_OF_STUDENTS):                                             # a, b, c, d & e instead of like
            print(listOfNames[w], sep = "", end = " ")                              # ['a', 'b', 'c', 'd', 'e'].
        elif (w+2 == NUMBER_OF_STUDENTS):
            print(listOfNames[w], sep = "", end = " & ")
        else:
            print(listOfNames[w], sep = "", end = ", ")

    print("(in descending alphabetical order).\n\n", sep = "", end = "")



def print_the_marks_obtained_after_sorting():


    marksObtained = MARKS_OBTAINED                                                  # To let MARKS_OBTAINED stay
                                                                                    # constant.

    print("The marks obtained by the student(s) enrolled in this course ",
          "is(are) :-\n", sep = "", end = "")


    marksObtained.sort()

    for u in range(NUMBER_OF_STUDENTS):                                             # To print marksObtained like
        if (u+1 == NUMBER_OF_STUDENTS):                                             # 1, 2, 3, 4 & 5 instead of like
            print(marksObtained[u], sep = "", end = " ")                            # [1, 2, 3, 4, 5].
        elif (u+2 == NUMBER_OF_STUDENTS):
            print(marksObtained[u], sep = "", end = " & ")
        else:
            print(marksObtained[u], sep = "", end = ", ")

    print("(in ascending order).\n", sep = "", end = "")


    marksObtained.reverse()

    for v in range(NUMBER_OF_STUDENTS):                                             # To print marksObtained like
        if (v+1 == NUMBER_OF_STUDENTS):                                             # 1, 2, 3, 4 & 5 instead of like
            print(marksObtained[v], sep = "", end = " ")                            # [1, 2, 3, 4, 5].
        elif (v+2 == NUMBER_OF_STUDENTS):
            print(marksObtained[v], sep = "", end = " & ")
        else:
            print(marksObtained[v], sep = "", end = ", ")

    print("(in descending order).\n", sep = "", end = "")



main()
def main():

    get_the_number_of_students_from_user()

    if (NUMBER_OF_STUDENTS > 0):
        get_the_list_of_names_from_user()
        get_the_list_of_marks_obtained_from_user()
        print_the_names_after_sorting()
        print_the_marks_obtained_after_sorting()
    else:
        print("The number of students should be greater than 0!\n",
              sep = "", end = "")



def get_the_number_of_students_from_user():

    global NUMBER_OF_STUDENTS

    NUMBER_OF_STUDENTS = int(input("Enter the number of students enrolled in "
                                   "this course: "))

    print("\n", sep = "", end = "")



def get_the_list_of_names_from_user():

    global LIST_OF_NAMES

    LIST_OF_NAMES = []

    for x in range(NUMBER_OF_STUDENTS):
        print("Enter the name of student no. ", x+1, ": ", sep = "", end = "")
        dummyVariable1 = input()
        LIST_OF_NAMES.append(dummyVariable1)

    print("\n", sep = "", end = "")



def get_the_list_of_marks_obtained_from_user():

    global MARKS_OBTAINED

    MARKS_OBTAINED = []

    for y in LIST_OF_NAMES:
        print("Enter the marks obtained by ", y, ": ", sep = "", end = "")
        dummyVariable2 = int(input())
        MARKS_OBTAINED.append(dummyVariable2)

    print("\n", sep = "", end = "")



def print_the_names_after_sorting():


    listOfNames = LIST_OF_NAMES                                                     # To let LIST_OF_NAMES stay
                                                                                    # constant.

    print("The name(s) of the student(s) enrolled in this course is(are) :-\n",
          sep = "", end = "")


    listOfNames.sort()

    for z in range(NUMBER_OF_STUDENTS):                                             # To print listOfNames like
        if (z+1 == NUMBER_OF_STUDENTS):                                             # a, b, c, d & e instead of like
            print(listOfNames[z], sep = "", end = " ")                              # ['a', 'b', 'c', 'd', 'e'].
        elif (z+2 == NUMBER_OF_STUDENTS):
            print(listOfNames[z], sep = "", end = " & ")
        else:
            print(listOfNames[z], sep = "", end = ", ")

    print("(in ascending alphabetical order).\n", sep = "", end = "")


    listOfNames.reverse()

    for w in range(NUMBER_OF_STUDENTS):                                             # To print listOfNames like
        if (w+1 == NUMBER_OF_STUDENTS):                                             # a, b, c, d & e instead of like
            print(listOfNames[w], sep = "", end = " ")                              # ['a', 'b', 'c', 'd', 'e'].
        elif (w+2 == NUMBER_OF_STUDENTS):
            print(listOfNames[w], sep = "", end = " & ")
        else:
            print(listOfNames[w], sep = "", end = ", ")

    print("(in descending alphabetical order).\n\n", sep = "", end = "")



def print_the_marks_obtained_after_sorting():


    marksObtained = MARKS_OBTAINED                                                  # To let MARKS_OBTAINED stay
                                                                                    # constant.

    print("The marks obtained by the student(s) enrolled in this course ",
          "is(are) :-\n", sep = "", end = "")


    marksObtained.sort()

    for u in range(NUMBER_OF_STUDENTS):                                             # To print marksObtained like
        if (u+1 == NUMBER_OF_STUDENTS):                                             # 1, 2, 3, 4 & 5 instead of like
            print(marksObtained[u], sep = "", end = " ")                            # [1, 2, 3, 4, 5].
        elif (u+2 == NUMBER_OF_STUDENTS):
            print(marksObtained[u], sep = "", end = " & ")
        else:
            print(marksObtained[u], sep = "", end = ", ")

    print("(in ascending order).\n", sep = "", end = "")


    marksObtained.reverse()

    for v in range(NUMBER_OF_STUDENTS):                                             # To print marksObtained like
        if (v+1 == NUMBER_OF_STUDENTS):                                             # 1, 2, 3, 4 & 5 instead of like
            print(marksObtained[v], sep = "", end = " ")                            # [1, 2, 3, 4, 5].
        elif (v+2 == NUMBER_OF_STUDENTS):
            print(marksObtained[v], sep = "", end = " & ")
        else:
            print(marksObtained[v], sep = "", end = ", ")

    print("(in descending order).\n", sep = "", end = "")



main()
```
Source Link

Sort and reverse lists

def main():

    get_the_number_of_students_from_user()

    if (NUMBER_OF_STUDENTS > 0):
        get_the_list_of_names_from_user()
        get_the_list_of_marks_obtained_from_user()
        print_the_names_after_sorting()
        print_the_marks_obtained_after_sorting()
    else:
        print("The number of students should be greater than 0!\n",
              sep = "", end = "")



def get_the_number_of_students_from_user():

    global NUMBER_OF_STUDENTS

    NUMBER_OF_STUDENTS = int(input("Enter the number of students enrolled in "
                                   "this course: "))

    print("\n", sep = "", end = "")



def get_the_list_of_names_from_user():

    global LIST_OF_NAMES

    LIST_OF_NAMES = []

    for x in range(NUMBER_OF_STUDENTS):
        print("Enter the name of student no. ", x+1, ": ", sep = "", end = "")
        dummyVariable1 = input()
        LIST_OF_NAMES.append(dummyVariable1)

    print("\n", sep = "", end = "")



def get_the_list_of_marks_obtained_from_user():

    global MARKS_OBTAINED

    MARKS_OBTAINED = []

    for y in LIST_OF_NAMES:
        print("Enter the marks obtained by ", y, ": ", sep = "", end = "")
        dummyVariable2 = int(input())
        MARKS_OBTAINED.append(dummyVariable2)

    print("\n", sep = "", end = "")



def print_the_names_after_sorting():


    listOfNames = LIST_OF_NAMES                                                     # To let LIST_OF_NAMES stay
                                                                                    # constant.

    print("The name(s) of the student(s) enrolled in this course is(are) :-\n",
          sep = "", end = "")


    listOfNames.sort()

    for z in range(NUMBER_OF_STUDENTS):                                             # To print listOfNames like
        if (z+1 == NUMBER_OF_STUDENTS):                                             # a, b, c, d & e instead of like
            print(listOfNames[z], sep = "", end = " ")                              # ['a', 'b', 'c', 'd', 'e'].
        elif (z+2 == NUMBER_OF_STUDENTS):
            print(listOfNames[z], sep = "", end = " & ")
        else:
            print(listOfNames[z], sep = "", end = ", ")

    print("(in ascending alphabetical order).\n", sep = "", end = "")


    listOfNames.reverse()

    for w in range(NUMBER_OF_STUDENTS):                                             # To print listOfNames like
        if (w+1 == NUMBER_OF_STUDENTS):                                             # a, b, c, d & e instead of like
            print(listOfNames[w], sep = "", end = " ")                              # ['a', 'b', 'c', 'd', 'e'].
        elif (w+2 == NUMBER_OF_STUDENTS):
            print(listOfNames[w], sep = "", end = " & ")
        else:
            print(listOfNames[w], sep = "", end = ", ")

    print("(in descending alphabetical order).\n\n", sep = "", end = "")



def print_the_marks_obtained_after_sorting():


    marksObtained = MARKS_OBTAINED                                                  # To let MARKS_OBTAINED stay
                                                                                    # constant.

    print("The marks obtained by the student(s) enrolled in this course ",
          "is(are) :-\n", sep = "", end = "")


    marksObtained.sort()

    for u in range(NUMBER_OF_STUDENTS):                                             # To print marksObtained like
        if (u+1 == NUMBER_OF_STUDENTS):                                             # 1, 2, 3, 4 & 5 instead of like
            print(marksObtained[u], sep = "", end = " ")                            # [1, 2, 3, 4, 5].
        elif (u+2 == NUMBER_OF_STUDENTS):
            print(marksObtained[u], sep = "", end = " & ")
        else:
            print(marksObtained[u], sep = "", end = ", ")

    print("(in ascending order).\n", sep = "", end = "")


    marksObtained.reverse()

    for v in range(NUMBER_OF_STUDENTS):                                             # To print marksObtained like
        if (v+1 == NUMBER_OF_STUDENTS):                                             # 1, 2, 3, 4 & 5 instead of like
            print(marksObtained[v], sep = "", end = " ")                            # [1, 2, 3, 4, 5].
        elif (v+2 == NUMBER_OF_STUDENTS):
            print(marksObtained[v], sep = "", end = " & ")
        else:
            print(marksObtained[v], sep = "", end = ", ")

    print("(in descending order).\n", sep = "", end = "")



main()

I started programming in Python after learning the basics of C, which is why I like the user-defined functions to be described after the main() function's job is over. Also, I like to specify the sep and end parameters of every print() function in my programs.

After some research, I came to know that the majority of programmers stick to a characters-per-line limit (80, 120, etc.), while others don't bother with such a limit. I have decided to limit my lines to 80 characters (if there are no in-line comments), or to 120 characters (including in-line comments). Using this style makes codes look very neat and easy to understand, in my opinion.