Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Apprendre Challenge 2 | Arguments or Parameters
Python Functions: From Zero to Hero

book
Challenge 2

Tâche

Swipe to start coding

You have to implement a function called function(), which takes the dictionary as an argument, goes through all the values in the dictionary (take a hint, if you have some difficulties in this moment) and displays the pair from the dictionary in which key = Canada.

To check, take such a dictionary:

{'France': 'Paris', 'Germany': 'Berlin', 'Canada': 'Ottawa'}

Solution

def function(dict):
for key, value in dict.items():
if key=='Canada':
print(f'The capital of Canada is {value}')

function({'France': 'Paris', 'Germany': 'Berlin', 'Canada': 'Ottawa'})

Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 2. Chapitre 3
single

single

# Write your code below
def ___(dict):
___ key, value in dict.___():
if ___ == '___':
print(___'The capital of Canada is {___}')
# Testing
function({'France': 'Paris', 'Germany': 'Berlin', 'Canada': 'Ottawa'})

Demandez à l'IA

expand

Demandez à l'IA

ChatGPT

Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion

some-alt