The program prompts the user to enter a limit l using the input function, which returns the user's input as a string. The string is then cast to an integer using the int function. A dictionary d is created, and a for loop is used to iterate over the range of numbers from 1 to l + 1. For each number in the range, the loop adds a key-value pair to the dictionary, where the key is the number and the value is the square of the number.
Finally, the dictionary is printed to show the result. In summary, the program demonstrates how to create a dictionary with keys and values based on a calculation, and how to use a for loop to add key-value pairs to a dictionary in Python.
l=int(input("Enter the Limit : ")) d = dict() for x in range(1,l+1): d[x]=x*x print(d)
Enter the Limit : 5 {1: 1, 2: 4, 3: 9, 4: 16, 5: 25}
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions