From e50619abedcc5de224afad7a3c346f4cc460eb27 Mon Sep 17 00:00:00 2001 From: Aaron <92693553+aquatichan@users.noreply.github.com> Date: Fri, 17 Oct 2025 02:08:27 +0000 Subject: [PATCH] Pending changes exported from your codespace --- .devcontainer/devcontainer.json | 2 +- lesson8_challenge.py | 62 +++++++++++++++++++++++++++++++ main.py | 65 +++++++++++++++++++++++++++------ 3 files changed, 117 insertions(+), 12 deletions(-) create mode 100644 lesson8_challenge.py diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 7dd78e7..3b4327e 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -26,7 +26,7 @@ "!LICENSE" ], "terminal.integrated.defaultProfile.linux": "zsh", - "editor.inlineSuggest.enabled": true, + "editor.inlineSuggest.enabled": false, "editor.copyWithSyntaxHighlighting": false, "editor.wordWrap": "on", "editor.linkedEditing": true, diff --git a/lesson8_challenge.py b/lesson8_challenge.py new file mode 100644 index 0000000..aed0cf9 --- /dev/null +++ b/lesson8_challenge.py @@ -0,0 +1,62 @@ +# I will be doing Challenge #4: Capital Letter Index. + +''' +Description: Write a function that takes a single string as an argument and returns a list of all the indexes in the string that have capital letters. +Summary: Make a function that returns the indexes in which the string has capital letters. +Input: String (User input is allowed but not required). +Output: Integer list +Edge cases: Empty string, number string +Coding keywords needed: def, return, print, for loop, if +Coding functions needed: str.isupper() + +Version 1: + +def capital_indexes(string): + uppercase_chars = [] + for i in range(len(string)): + if string[i].isupper() == True: + uppercase_chars.append(i) + if len(uppercase_chars) == 0: + return "List is empty" + return uppercase_chars + +user = input() +print(capital_indexes(user)) + +Version 2: + +def capital_indexes(string): + uppercase_chars = [] + for index, char in enumerate(string): + if char.isupper(): + uppercase_chars.append(index) + if len(uppercase_chars) == 0: + return "List is empty" + return uppercase_chars + +user = input() +print(capital_indexes(user)) + +''' + +from string import ascii_uppercase +def capital_indexes(str_final): + return [i for i in range(len(str_final)) if str_final[i] in ascii_uppercase] + +user = input("this is your input >>") +print(capital_indexes(user)) + + + + +''' +ARRAY OF UPPERCASE = [] +FUNCTION capital_indexes(STRINGVARIABLE): + FOR CHAR IN STRINGVARIABLE: + IF CHAR.isupper() == TRUE: + ARRAYOFUPPERCASE.append(STRINGVARIABLE.INDEXOF(CHAR)) + IF ARRAYOFUPPERCASE.LENGTH == 0: + RETURN "LIST IS EMPTY" + RETURN ARRAYOFUPPERCASE = [] + +''' diff --git a/main.py b/main.py index 44fcc27..0bfd121 100644 --- a/main.py +++ b/main.py @@ -1,5 +1,4 @@ - -""" +''' Welcome to Elite 101 this program is a starter for your chatbot project. The starter prompts the user to enter their name and then greets them with a personalized message. @@ -10,18 +9,62 @@ Execution: When the script is run directly (not imported as a module), it will execute the main() function. -""" -def get_user_name(): - return input("Please enter your name: ") + def get_location(): + return input("Please enter your location: ") + + + def get_user_name(): + return input("Please enter your name: ") + + def greet_user(name): + print(f"Hello, {name}, how are you?") + + def main(): + user_name = get_user_name() + greet_user(user_name) + + if __name__ == "__main__": + main() +''' + +import requests # pip install requests, an external library for making HTTP requests + +def ip_to_location(ip: str) -> dict: # function expects a string and returns a dictionary + ''' + Converts a valid IP address to latitude, longitude, city, and country + Uses the ipapi.co API to fetch location data + ''' + try: + url = f"https://ipwho.is/{ip}" # Construct the API URL + response = requests.get(url, timeout=10) # Make a GET request to the API with a timeout of 10 seconds + response.raise_for_status() # Raise an error in case of bad responses + data = response.json() # Parse the JSON response + + return { + "latitude": data.get("latitude"), + "longitude": data.get("longitude"), + "city": data.get("city"), + "country": data.get("country"), + "zip_code": data.get("postal") + } + + except Exception as e: + return {"Error": str(e)} -def greet_user(name): - print(f"Hello, {name}, how are you?") +def geolocation_api(lat, long, keywords=["school", "university", "college"], radius_mi=15): + pass -def main(): - user_name = get_user_name() - greet_user(user_name) if __name__ == "__main__": - main() + print(geolocation_api(40.7128, -74.0060)) # Example coordinates for New York City + ''' + # user_ip = requests.get("https://api.ipify.org").text + This doesn't work if you're running this using Github Codespaces or any other cloud IDE + because the IP address returned will be that of the cloud IDE, not your local computer. + If you want to test this, download the code and run it locally on your computer. + Therefore, we simply will prompt the user to enter their IP address manually. + ''' + user_ip = input("Please enter your IP address (nothing will be stored): ") + print(ip_to_location(user_ip))