Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
62 changes: 62 additions & 0 deletions lesson8_challenge.py
Original file line number Diff line number Diff line change
@@ -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 = []

'''
65 changes: 54 additions & 11 deletions main.py
Original file line number Diff line number Diff line change
@@ -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.

Expand All @@ -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))