Skip to content

Instantly share code, notes, and snippets.

@solen003
Created July 15, 2018 13:36
Show Gist options
  • Save solen003/94fed33391513afdb603752069437b94 to your computer and use it in GitHub Desktop.
Save solen003/94fed33391513afdb603752069437b94 to your computer and use it in GitHub Desktop.
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. Suppose the following input is supplied to the program: 8 Then, the output should be: {1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64}
number = int(input("Type a number: "))
numberDict = {}
for i in range(1, number+1):
numberDict[i] = i*i
print(numberDict)
@sanouch22
Copy link

number = int(input("Type a number: "))

numberDict = {3}
for i in range(1, number+1):
numberDict[i] = i*i

print(numberDict)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment