Skip to content

Commit 9493b2b

Browse files
committed
add something to learn
1 parent cf98b2b commit 9493b2b

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

basics/Lambda/challenge.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
11
tripled = lambda x: x*3
2-
num = int(input("Enter a number: "))
3-
print(tripled(num))
4-
# What is the output of this code?
2+
print(tripled(int(input("Enter a number: "))))
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import requests
2+
3+
# Function to fetch Pokémon data with a callback
4+
def fetch_pokemon(name, callback):
5+
url = f'https://pokeapi.co/api/v2/pokemon/{name}'
6+
response = requests.get(url)
7+
8+
if response.status_code == 200:
9+
data = response.json()
10+
callback(data) # Call the callback function with fetched data
11+
else:
12+
print("Character not found")
13+
14+
# Lambda function as a callback to process and print the data
15+
process_pokemon = lambda data: (
16+
print(f"Name: {data['name']}\nAbilities:"),
17+
print(data['abilities']['ability']['name']) ,
18+
19+
)
20+
21+
# Get user input
22+
userInput = input("Enter Poke Character: ").strip().lower()
23+
24+
# Call fetch_pokemon with the callback
25+
fetch_pokemon(userInput, process_pokemon)

0 commit comments

Comments
 (0)