+ 2

# Write a function that accepts a number as argument and returns the square of the number. For example if the number passed to the

My code is working but due to the instructions I get the error which includes the function arguments. Please help! n=int(input()) def square_num(): a = n**2 my_result = a return my_result print(square_num())

1st Feb 2022, 3:06 PM
Knowledge Is Power + 4
Save your code in code playground and share it's link here. You've used n inside your function, but where did you declare it inside the function? Your function is a seperate block that doesn't know about the variables and functions outside of it. So you need to pass in the variable n so that your function knows what n is. It'll something like the below snippet: ... def square_num(n): ... Hope you understood the explanation. Feel free to ask doubts if any
1st Feb 2022, 3:24 PM
Rishi + 2
What are the instructions? Use description place to write full question??
1st Feb 2022, 3:21 PM
Jayakrishna 🇮🇳
+ 2
# yes, code works but there expected clean code is : def square_num(n): a = n**2 my_result = a return my_result n = int( input() ) print( square_num(n) )
1st Feb 2022, 3:35 PM
Jayakrishna 🇮🇳
+ 1
The whole question is Write a function that accepts a number as argument and returns the square of the number. For example if the number passed to the function is 5 then your function should return 25
1st Feb 2022, 3:32 PM
Knowledge Is Power + 1
every syntax matters! my first practice with function. got my mistake, thank you for your support! appreciate it!
1st Feb 2022, 3:44 PM
Knowledge Is Power 