0

Example:

test = int(input("Enter a number"))
test2 = test * 24
print(test2)

when i enter a float number like 0.10 i get this error:

ValueError: invalid literal for int() with base 10: '0.10'

test = int(float(input("Enter a number"))) makes 0.10 to 0

I want the output like this:

>>> 2.4

How do i fix?

2
  • 8
    You don't want an int at all, you want a float. Just do test = float(input("Enter a number")). Commented May 26, 2021 at 20:00
  • 3
    If you don't want an int then don't convert it to an int. Just do float(input("Enter a number")) Commented May 26, 2021 at 20:00

2 Answers 2

2

now it will work

test = float(input("Enter a number"))
test2 = test * 24
print("%.1f"%test2)
Sign up to request clarification or add additional context in comments.

Comments

1

You need a float as an input so use:

test = float(input("Enter a number"))

Comments

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.