File tree Expand file tree Collapse file tree 1 file changed +8
-8
lines changed Expand file tree Collapse file tree 1 file changed +8
-8
lines changed Original file line number Diff line number Diff line change 55
66*** Define a function which can print a dictionary where the keys are numbers between 1 and 20 (both included) and the values are square of keys.***
77
8-
98----------------------
10- ### Hints:
11- ####
12- Use dict[ key] =value pattern to put entry into a dictionary.
13- Use ** operator to get power of a number.
14- Use range() for loops.
15-
9+ ### Hints: Use dict[ key] =value pattern to put entry into a dictionary.Use ** operator to get power of a number.Use range() for loops.
1610-------------------
17- Solution
11+ ** Main Author's Solution: Python 2
12+ ```
1813def printDict():
1914d=dict()
2015for i in range(1,21):
@@ -26,4 +21,9 @@ printDict()
2621----------------
2722** My Solution: Python 3**
2823```
24+ def printDict():
25+ dict={i:i**2 for i in range(1,21)} # Using comprehension method and
26+ print(dict)
27+
28+ printDict()
2929```
You can’t perform that action at this time.
0 commit comments