23 AnswersNew Answer
23 AnswersNew Answer
print(sum([(x+7)**2 for x in range(1,18)])) You can write like this in only one line code
So basically, you want to just put this in code playground and run it?
Khushan x=0 for r in range (1,18): r = (r+7)**2 x+=r print(x) Tomiwa Joseph don't suggest to use a Function name as identifier Ex. sum
Yeah 𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 my bad
𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 I wanted him to figure that out all by himself 😃😃😃
Here is a function that will calculate the question. I have included all arguments so you can use it flexibly. def square_sum(range_start, range_end, exponential_power, add_num): x = 0 for r in range(range_start, range_end): x = x + ((r + add_num)**2) print(x) square_sum(1, 8, 2, 7) >>> 875 #for range (1, 2, 3, 4, 5, 6, 7), power raise to 2, the number added to r, 7 in your case square_sum(1, 18, 2, 7) >>> 4760
Answer Find all the answer in range of 1 to 18 and then add all the required number So the code is X= (1+7)**2 = 64 ..... .... .... .... ... ... .... .... .. ... ... ... ... .... ... .... X=(18+7)**2 = 15625 Print X+X+....+....+......+....+....+.....+...+.....+....+...+X
Harshit Singh I appreciate your efforts bt I think you should learn mathematics too with programming..
Sum=0 >>> for r in range(1,18,1): Sum=Sum+((r+7)**2) >>> print(Sum)
Khushan it looks like assignment , show your attempt for further help
𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 Kiibo Ghayal it's not an assignment I was doing mathematics and this was a calculation so I thought let's use my Python knowledge to get an answer instead of that calci. I was able to get the square bt can't add them up.
Khushan I want to see how you have used your Python knowledge.So share your attempt here
𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 Oh.. Pls don't laugh I don't have any computer background and everything I have learned is using SoloLearn. Here's the code I did. for r in range in (1,18): r = (r+7)**2 x = r+r print(x) It gives me square and don't add them.
Khushan here is a hint: addition = 0 for q in range(1,18): x = (q+7)**2 .....find a way to add x to addition😃 Hope this helps.
𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 I also try this it won't work for me.
Khushan Save this code in code playground and click on run button If it won't work, share its link here
𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 I got my error. TY
Khushan check this list out: print([(x+7)**2 for x in range(1,18)]) If this are the numbers you want to add, add them. 𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 I normally wouldn't write for loops like that, that's why I made that simple mistake. Comprehensions made me lazy😃😅
Tomiwa Joseph can u read mind? I was just trying to convert it in list so I could use sum function and u did it already. TY
Learn Playing. Play Learning
Send us a message