Module 5.3, step 11

5-3
module-5

#1

I’ve been stuck on the problem for Modue 5.3, step 11 where we are trying to calculate the diameter for a circle using the circumference. I can’t quite figure out how to get it to print the correct info. I put a screen shot of the closest code I can get to work that does not also result in an error. I’m not sure if the issue is with what I’m asking to print or with my def calculate_diameter code or something else. Any tips on what I’m missing? Seems be the the same issue I’m having w/ module 5.3, step 16.

Instructor edit: Removed screenshot of code that was very close to the solution to avoid giving away answers. The original poster’s terminal was printing <function calculate_diameter at 0x7f0465ab2f8>. If you’re having a similar issue, check your print statement where you call the function.


#2

One thing to keep in mind is that input is always going to be a string. So, if the user is inputting a string, rather than an integer-- how would that affect the way the code would operate?


#3

After some research and a little input from a friend, I got a correct answer with the code below. Looks like defining the input was the issue. I used float and that work.

Moderator edit: Screenshot removed to avoid just giving the answer to future users with a similar question. If you have a problem similar to DomWith-a-ck, make sure you’re checking the statement where you request input as well as the print statement, where you call the function.


#4

I give up on the fill in the blank that relates to this question. The code runs but the answers are not correct on the fill in the blank. There are a few parts of the fill in I am sure of and others I have tried different answers. Maybe the ones I’m sure of are wrong.


#5

I’m having the same problem. My solution doesn’t match the fill in the blanks, but it works as it should. https://repl.it/@MeganMcCarron/53Step10

I rewrote it to match what the fill-in-the-blanks want, got another working bit of code, but can’t get the right answers for the fill in the blank.


#6

the code works. but these fill in the blanks are too dang sensitive. i cant figure out how to type it out so it works.


#7

this gives me the answer we’re looking for but the fill in the blanks POS is too sensitive. and before i get “oh dont give the answer away” this clearly has to be wrong so i havent given anything but what not to do.

def calculate_diameter(circumference):
pi= 3.14
circumference = user_input
diameter = circumference / pi
return diameter

user_input = int(input(“what is circumference of circle?”))
print (calculate_diameter(int))


#8
  1. I think we aren’t supposed to give answers so i’ll say take another look at what you’re passing to calculate_diameter in your print line, “int” hasn’t been defined or assigned any value (also I think it’ll throw a fit if we name a variable int in python). On line 3 you give circumference the value of user_input so I think you know what you want but did the coding equivalent of misspeaking

  2. Less sure about this but I think you can drop the “circumference = user_input” on line 3 after you get issue #1 fixed.


#9

that isnt right cause it doesnt return with the right answer. so somewhere it has to be told to transfer into an integar, plus that leaves circumference undefined cause the user input isnt plugged in anywhere else.

UPDATE: i tried what you suggested and i was right. removing line 3 makes it so that circumference is NOT a defined Variable. and removing int in the print statement means that it doesn’t print an integar. i looked at maybe changing the math equation but then none of the multiple choice options have the right equation to do it so it has to be D=C/pi.


#10

When a function is defined, such as in the line def calculate_diameter(circumference):, the variable inside of those parentheses is already provided for the body of the function to use. So, you don’t need to redefine what circumference would equal because that will be provided when you call the function.

When you use calculate_diameter(int)), you’re passing int to the calculate_diameter function and telling the computer to run the code in that function and replace any places where the variable inside the parentheses, circumference, is used.

I know that these fill-in-the-blank problems can be frustratingly sensitive, but sadly that’s the world of coding. Computers can’t figure out what you mean unless you provide exactly the right instructions with the exact correct syntax.

Send me a message if you need further clarification, I don’t want to clog up the thread too much.


#11

I am stumped by this problem. I have been working on it for two days. I have tried to google similar problems and can’t seem to find an answer. My code continues to return this error message <function calculate_diameter at 0x7fda8c5fdbf8>. Not sure what to do? Here is a copy of my code so far. I feel like I missing something but can’t seem to figure it out.
def calculate_diameter(circumference):
pi = 3.14
diameter = circumference / pi
return(diameter)
user_input = float(input("What is the circumference of the circle? "))
print(calculate_diameter)


#12

That’s not actually an error message, that’s your computer attempting to print the function, calculate_diameter, instead of what the function returns, which would hopefully just be a value.

Think about how you would run the function calculate_diameter using the value that the user entered, then worry about printing that value. This could technically be split into two steps, but it’s pretty easy to consolidate into one line of code.


#13

e: code removed

I don’t get what i am doing wrong ?


#14

What kind of error are you getting?


#15

Again, the code looks good to me, so I don’t know what’s going on here-- the course is not accepting this one? Same as your last post, it seems correct.

(Note: they will likely remove your code, as we are not to post large chunks of solution code on the site here.)


#16

I am having a bunch of problems with this one. I can get to the part about printing but I cant seem to figure out why I cant get it to print
I just dont understand what I am supposed to put in the print spot. I feel like I have everything leading up to that correct but still get that diameter isnt defined


#31

Hey Adam I had the same problem as this individual but my code is a little different. I don’t quite understand what you are trying to tell him to do but I am receiving the same answer he got.


#32

can you help me in 5.3 step 16


#33

You need to copy and paste just the function itself. There should be a ‘def functionname’ line and then your calculations. And, remember to indent.