1

could not find this question answered by search. I am trying to learn some Python and need your help this this function:

def roundtest():
    i = round(raw_input("call a number: "), 2)
    print i

My input & the error I get:

call a number: 1.2222

TypeError: a float is required

Thank you for your help

0

1 Answer 1

4

raw_input returns a string, which you then have to parse in to a float, like so:

def roundtest():
    i = round(float(raw_input("call a number: ")), 2)
    print i
Sign up to request clarification or add additional context in comments.

1 Comment

@bermudaa make sure you accept the answer to indicate it was helpful to other readers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.