Module 5.3 step 16

5-3
module-5

#1

I have tried a few codes but am not getting the stdin stdout clue. Where did I miss that in the lessons? I’ve reviewed them and am still coming up short.


#2

This problem is set up so that the automated grader already provides input and output functionality, so all we’re asking you to do is fill in the find_area function. If you provide your own request for user input or print statement, the grader won’t know what to do with your statements having already performed those tasks.

All you need here is something to compute the area of the circle and some sort of return statement to provide that value to whatever called your function. The grader then runs tests by calling find_area() with various different inputs and testing its response against the expected responses.


#3

I’m finding this step very confusing. I’m using similar code from the previous steps, but still getting a Syntax_error. Can anyone guide me on ideas to fix?


#5

To retrieve a user input, there is a different code. But to define the function, you don’t need that-- just to define the relationship between a radius and an area of a circle. I think you are making it harder on yourself than you need to.


#6

I simplified it based on what you said and was able to a working code for step 15. Thanks!

However, when I plug it by copying and pasting like suggested on step 16, I am getting an error that reads…

Failed test #1. Runtime error
Traceback (most recent call last):
File “jailed_code”, line 7, in
user_input = int(input(“What is the radius of a circle?”))
EOFError: EOF when reading a line

I am not sure how to solve this considering it’s literally the same code and I checked the indentation. I ran it several times in 15 to make sure it worked. I would post a screenshot but I don’t want to post so close to the solution. I realize it has to be one small thing to fix but I can’t figure out what.


#7

Also, I just realized this isn’t worth any points. So since I know the code I wrote worked for the previous page, I am going to move on but man that was frustrating for a minute there!


#8

OK! At any rate, your code looks correct for an input, but I think in this case they are just asking you to define the function, not to retrieve an input (or to call the function, either).


#9

Ah again, I just made things too complicated. :rofl:

Thanks!


#10

inputs(radius) are already given in the program. so we need to call the actual(area of the circle) function with the given radius… if the functional gets called and outputs the correct (mentioned) answer, then the tests says “pass”


#11

alright so here is a walk through of this

you are trying to find the area of a circle so lets look at the 2 possible formulas:

  • Area = pi * (radius **2)
  • Area = pi * ((diameter / 2) ** 2)

well pulling out a quick calculator tells me that with an input of 5 and an output of 78.5 that the first formula is the correct one, so lets code it

lets define the function (already done for you)

so what does the formula in order to calculate? Pi and Radius. One of those is already passed in the function header so lets define the other one.

alright so now that everything we need is defined lets tell the computer what the formula is.

so now that the computer has all the variables it needs and the formula, what are we trying to return?

Hope this helps


#12

This is what I have so far:

def find_area(radius):

pi = 3.14
area = int(pi * (radius**2)

user_input = int(input(“What is the radius”))

print (find_area(user_input))

please help


#13

The function needs to be returned. Declaring the area correctly is ok, but you have to use a “return” command to send that value back to the main code block.