+ 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.

14th Jun 2020, 6:12 AM
Nikhil Balai
Nikhil Balai - avatar
7 odpowiedzi
+ 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
14th Jun 2020, 6:48 AM
Raj Chhatrala
Raj Chhatrala - avatar
+ 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.
14th Jun 2020, 6:22 AM
Raj Chhatrala
Raj Chhatrala - avatar
14th Jun 2020, 6:29 AM
Tibor Santa
Tibor Santa - avatar
+ 1
Nikhil Balai 1. Change a = 0 to a = 1 2. In for loop use: range(int(x)+1): Instead of x
14th Jun 2020, 6:52 AM
Valmob101
Valmob101 - avatar
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
14th Jun 2020, 6:44 AM
Nikhil Balai
Nikhil Balai - avatar
0
🔫 Rick Grimes Thank you for the answer! It's working now 👍
14th Jun 2020, 6:54 AM
Nikhil Balai
Nikhil Balai - avatar
0
Valmob101 Certainly, otherwise it wouldn't have printed the last key value pair. Thank you !!
14th Jun 2020, 6:57 AM
Nikhil Balai
Nikhil Balai - avatar