Code comparison & explanation | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Code comparison & explanation

MY the first code doesnt work and the difference to the revised version is just the location of where the variables was declared. the first one was on the first lines and the second one was inside a function. can someone explain why this happens? thank you

8th Apr 2023, 2:54 PM
Earlninzkie 2002
Earlninzkie 2002 - avatar
2 Answers
+ 4
Firstly, make your code public and then, you can see '+' icon right side click on, then click insert code, and you can see on top 'hot today' drop-down menu and click on my code bits then share it
8th Apr 2023, 3:08 PM
Sakshi - avatar
Line 26 invokes the inputs function before the user inputs any value. Because of this, when called, the inputs function returns NaN. Meaning that back at line 26, the variables ef, radius, and angle are all assigned NaN. The inputs function is never invoked after the submit button is pressed. So when the user does enter any values, the variables(ef, radius, angle) are not updated. And the initial values(NaN) are used in the formula() code block resulting in NaN as output.
9th Apr 2023, 7:43 AM
ODLNT - avatar