Menu Close

Generate a Dictionary that Contains Numbers in the Form (x , x*x).

Python Program to Generate a Dictionary that Contains Numbers (between 1 and n) in the Form (x , x*x).

INPUT
5

OUTPUT
{1: 1, 2: 4, 3: 9, 4: 16, 5: 25}
N=int(input())
dict={}
for i in range(1,N+1):
    dict[i]=i**2
print(dict)

INPUT_1:
5

OUTPUT:
{1: 1,  2: 4,  3: 9,  4: 16,  5: 25}


INPUT_2:
10

OUTPUT:
{1: 1,  2: 4,  3: 9,  4: 16,  5: 25,  6: 36,  7: 49,  8: 64,  9: 81,  10: 100}


INPUT_3:
15

OUTPUT:
{1: 1,  2: 4,  3: 9,  4: 16,  5: 25,  6: 36,  7: 49,  8: 64,  9: 81,  10: 100,  11: 121,  12: 144,  13: 169,  14: 196,  15: 225}


INPUT_4:
9
OUTPUT:
{1: 1,  2: 4,  3: 9,  4: 16,  5: 25,  6: 36,  7: 49,  8: 64,  9: 81}


INPUT_5:
3

OUTPUT:
{1: 1,  2: 4,  3: 9}


ILLUSTRATION

Executed using python3

Morae Q!

  1. OS operating system module using path parameter.
  2. Find the smallest and largest integers after sorting using bubble sort.
  3. Find the integer and its number of occurrences.
  4. Algorithm complexity – Big O Notation with Examples.
  5. Linear search.
  6. Map module using series mapping and parallel mapping.
  7. Mapping and Transposing with Map Module.
  8. Map Module/built-in Function.
  9. Linux commands for managing files.
  10. Program which takes two lists and maps two lists into a dictionary.
  11. Splitting strings and substituting using regular expressions regex.
  12. Basics of regular expression Regex.
  13. Find the square value of the dictionary.
  14. Check whether the given key is present in the dictionary.
  15. Matching an expression only in specific places using regular expressions.
  16. Escaping special characters using regular expressions.
  17. Check the key.
  18. Grouping and sub-grouping using regular expressions.
  19. Generate a Dictionary that Contains Numbers in the Form (x , x*x).
  20. Algorithm complexity Big-Theta, Big-Omega and Big-O Notations.