Skip to content

Commit 32aa3fa

Browse files
committed
Completed Question 3
1 parent 7279a61 commit 32aa3fa

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

Q003.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Question 003
2+
3+
#Question:
4+
#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.
5+
#Suppose the following input is supplied to the program:
6+
#8
7+
#Then, the output should be:
8+
#{1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64}
9+
10+
# Get the input number
11+
print "Enter a number to create a dictionary up to: "
12+
inputNumber = int(raw_input())
13+
14+
# Create a dictionary to hold all the numbers
15+
dictionary = dict()
16+
17+
# Fill the dictionary with a for loop
18+
for count in range (1, inputNumber + 1):
19+
dictionary[count] = count * count
20+
21+
# Print the result to the user
22+
print dictionary

0 commit comments

Comments
 (0)