+ 1
I came across a python challenge online, where in we had to show the output using dictionary
Enter a number: 6 Output: {1:1, 2:4, 3:9, 4:16, 5:25, 6:36} The boundary of the key limit is to be set by taking input from the user.
7 Respuestas
+ 6
Nikhil Balai
You have 2 mistakes in your code.
1) you did not convert input to integer using int()
2) you have to use range() in for loop.
Fix
https://code.sololearn.com/cWBNFloTv3as/?ref=app
+ 6
So what's your question?
Do you have any doubt about challenege or are you getting any errors while coding it? You did not show your attempt as well.
Please make sure you link your code with what you have issue.
+ 4
You can find a full guide to dict comprehension here:
https://www.datacamp.com/community/tutorials/JUMP_LINK__&&__python__&&__JUMP_LINK-dictionary-comprehension
+ 1
Nikhil Balai
1. Change a = 0 to a = 1
2. In for loop use:
range(int(x)+1):
Instead of x
0
Yes, I had tried but the output terminal only prints the first key value pair.
Output was --> {0:0}
Link for my code below
https://code.sololearn.com/c71esMd4R64p/?ref=app
0
🔫 Rick Grimes
Thank you for the answer!
It's working now 👍
0
Valmob101
Certainly, otherwise it wouldn't have printed the last key value pair.
Thank you !!