livepython.net

110. Python Program to Create a Dictionary from Input

EasyDictionary

Overview

Your first dictionary, built from what the user types.

Problem Statement

Read a name, an age (a whole number) and a city, one per line. Store them in a dictionary with the keys "name", "age" and "city", in that order, with the age stored as a number. Print the dictionary, then the number of pairs in the format Pairs: 3. For example, for Sunny, 25 and Pune:

{'name': 'Sunny', 'age': 25, 'city': 'Pune'}
Pairs: 3

Use input() with no prompt text: the tests type the input for you, and a prompt would end up in your output.

Input

One value per line, in this order. Example:

Sunny
25
Pune

Output

The output for that example:

{'name': 'Sunny', 'age': 25, 'city': 'Pune'}
Pairs: 3

The tests try 3 different inputs.

Learn this firstChapter 13 · Python Dictionary: Store Data in Key-Value Pairs
solution.py
# write your code here

EXPECTED OUTPUT

1{'name': 'Sunny', 'age': 25, 'city': 'Pune'}
2Pairs: 3

YOUR OUTPUT

Press Run to see your output here. Lines are compared with the expected output.