New to Python (learning functions)

learning python and have been utilizing HackinScience, but I have been stumped on this question. Any suggestions on what I am doing incorrectly?

Hey there.

So, radius = float() what? You need to give it a number. Then call your function from within the print() function call.

Here is a very simple example:

def greet(name):
    response = f"Hello {name}. How are you?"
    return response

name = input("What is you name? ")


the line:

radius = float

you are setting the radius to the float type – you want to give it a value – like 1.2 or something.



Hi Lily, and welcome!

Three things you are doing wrong:

(1) Unless you use Photoshop to write your code, you should not post screenshots of code. Copy and paste it as text, between code fences, as described here:

Screen shots make it difficult for us to run your code if we need to, and discriminate against the blind and visually impaired who may be using a screen reader. (Yes, blind programmers exist.)

(2) Don’t make us guess what error you get. Its not always obvious or easy to guess. Copy and paste the entire traceback, if you get one, starting with the line “Traceback…” not just the last error message at the end.

(3) Tell us what result you expected, and what result you got instead.

In this case, I think I can probaby guess what error you are getting. It looks like you are doing this:

radius = float

and then you will probably get an error similar to:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for *: 'type' and 'float'

Am I close?

Look at the value of your radius: you set it to float. What value do you expect it to have?

float is a type or class in Python, that is, it tells you what type of thing a value is. Values can be strings, integers (whole numbers), lists, floats, or many others.

Try setting radius = 5.2 instead, for example.


Apologies :sweat_smile: and thank you!
I have pasted my new code with a value set to radius.

import math
def circle_perimeter(radius):
    circumference = 2 * math.pi * radius
    return circumference

radius = float(2.5)

as for the traceback error

    circumference = 2 * math.pi * radius
TypeError: unsupported operand type(s) for *: 'float' and 'type'

Thanks Rob!
I appreciate the example, as I am new and setting sail to learn Python on my own this really helps a lot!!

1 Like

You are most welcome and enjoy the journey. Remember that it’s a marathon, not a sprint and that you’ve made a very good start.

To add: okay, so you’ve set the radius, so now you can do:


… or…

radius = float(2.5)
rad = circle_perimeter(radius)

2.5 is a literal for the float of value 2.5 – you con’t need to call float() on it:

radius = 2.5

is just fine. The official tutorial is not a bad place tp start: