# -*- coding: utf-8 -*-
"""
Excercise 3-8 "See the World from Python Crash Course 3rd Ed by Eric Matthes

This program promts a list of places the user wants to go, then does some things to the list

Also an exploration into the differences between functions and methods.

Ordinal ordinal function from Ben Davis on Stack Exchange
https://stackoverflow.com/questions/9647202/ordinal-numbers-replacement

Created on Sunday Aug 04, 2024 - 12:20

@author: Volta
"""

print("How many places would you like to visit (positive integer)")

#Promts user input, checks if user input is a positive integer, makes user correct input
passes_int = False
passes_pos = False
while passes_int != True or passes_pos != True:
    try:
        num_places = int(input())
    except:
        print("Number not an integer, try again")
        passes_int = False
        continue
    else:
        passes_int = True

    if num_places < 1:
        print("Number not positive, try again")
        passes_pos = False
    else:
        passes_pos = True


#Defining function to make ordinals
def ordinal(n: int):
    if 11 <= (n % 100) <= 13:
        suffix = 'th'
    else:
        suffix = ['th', 'st', 'nd', 'rd', 'th'][min(n % 10, 4)]
    return str(n) + suffix


#Making the list

places = []

input_order = 1
while num_places > 0:
    print("What's the", ordinal(input_order), "place you want to go?")
    places.append(input())

    input_order = input_order + 1
    num_places = num_places - 1

#Transformation and printing

print("Original order:", places)
print("Sorted list:", sorted(places))
print("Original order:", places)
print("Sorted list in reverse:", sorted(places, reverse=True))
print("Original order:", places)

places.reverse()
print("Reversed order:", places)

places.reverse()
print("Re-reversed order:", places)

places.sort()
print("Perma-sorted list:", places)

places.sort(reverse=True)
print("Reverse alphabetical order:", places)

""" Functions vs Methods
A function puts the variable as an argument in the parentheses - has it's own unique value as an output
A method goes after the variable with a "." in between - changes the value of the variable
sorted() is a function which can take 'reverse' as an argument, .sort() & .reverse() are methods and .sort() can
also take 'reverse' as an argument.
 """