Optional Part - Problem 1

Hi, I am stuck with the optional part problem one. No problem to create the dictionary with the keys and values, but I have no idea how to print each of them in a specific format with the data type at the end. Can someone help please ? Thanks a lot.


you just need to declare it like so:

type(v). #v for values

is this what you wanted?

Not really, I need help in the combination of the loop, right syntax and data type. I might not express myself very clearly, you might understand better what is required here:

yes. you just include the type(v) in the code.

for k,v in person.items():
     print("The key {} has the value {} of the type {}".format(k,v,type(v)))
1 Like

Ok that’s great thank you ! One last detail, how do you print the quotation marks using this method, so that the output is printing: (for the 1st iteration)

The key “Name” has the value “Derek” of the type “<class ‘str’>”

you can do the below:

for k,v in dicts.items():
     print("The key '{}' has the value '{}' of the type '{}'".format(k,v,type(v)))

or you can place single quotes on the outside and double quotes inside

for k,v in dicts.items():
     print('The key "{}" has the value "{}" of the type "{}"'.format(k,v,type(v)))
1 Like

Perfect, I didn’t know we could do it this way, thanks a lot for your help !

1 Like

Optional Questions are too much interesting to solve.

1 Like

That’s true @adityamodi1113! Also welcome to the community.