Skip to content

Commit b88740e

Browse files
committed
add Q3.py
1 parent 00aada2 commit b88740e

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

exercises/Q3.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
'''
2+
Question 3
3+
Level 1
4+
5+
Question:
6+
With a given integral number n, write a program to generate a dictionary that contains (i, i*i) such that is an integral number between 1 and n (both included). and then the program should print the dictionary.
7+
Suppose the following input is supplied to the program:
8+
8
9+
Then, the output should be:
10+
{1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64}
11+
12+
'''
13+
14+
15+
def integral(x):
16+
17+
if x > 0 and isinstance(x, int):
18+
return {y: y**2 for y in range(1, x+1)}
19+
else:
20+
return {0: 0}
21+
22+
print(integral(8))

0 commit comments

Comments
 (0)