# -*- coding: utf-8 -*-
"""
Remix of my program for excercise 3-8 "See the World from Python Crash Course
3rd Ed by Eric Matthes
More list nonsense

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

Edited to comply with PEP8 (I think)

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

Created on Tuesday Aug 06, 2024 - 13:00

@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

#starting off with the list that's generated in 3-8 See the World
#Doing some different things with it

#for loop to say some things about the places
for place in places:
    print(f"{place.title()} is a very cool place!")

print(places)

#^In this case, the method "title()" doesn't permanently act on the elements in
# the list

#prints a version of the list sorted by length of the elements
#first one doesn't permanently modify the list
print(sorted(places, key=len))
print(places)

#the second one does
places.sort(key=len)
print(places)

"""
Both the sorted() function and the .sort() method can take an argument "key="
This takes some value from each element and sorts it by that value - in this
case, the length of each element
Does this key need to be something that returns an integer value???
"""

"""
This takes the new sorted list, then generates a new list with each
element corresponding to the length of each element in the original list

It uses the append() method first, and a list comprehension second to accomplish
 the same thing
"""

places_length = []
for place in places:
    places_length.append(len(place))
print(places_length)

places_length2 = [len(place) for place in places]
print(places_length2)
      
#using a list comprehension to make a list of the cubes of multiples
# of .5 from 0 to 10
cubes_10 = [(x/2)**3 for x in range(1,21)]
print(cubes_10)