File tree Expand file tree Collapse file tree 2 files changed +26
-3
lines changed Expand file tree Collapse file tree 2 files changed +26
-3
lines changed Original file line number Diff line number Diff line change 1
1
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: " ))))
Original file line number Diff line number Diff line change
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' ]} \n Abilities:" ),
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 )
You can’t perform that action at this time.
0 commit comments