PYTON CODERS I NEED HELP I WILL GIVE BRAINLIEST!!! Why is this python code giving me problems?
This is having the user input a decimal number and the code has to round it up to the 2nd decimal place. This code is giving me problems, please fix it.

num3 = int(input("Please input a decimal number:")

num3 = int(round(num3, 2))

print ("your decimal rounded to the 2nd decimal place is:", x)

Respuesta :

Answer:

num3 = float(input('Insert a decimal: '))

num3 = round(num, 2)

print(f"You rounded decimal is: {num3}")

Explanation on why this works:

This block of code resembles a decimal from user input and round it to its nearest 10th. Let me explain the flaws in the original:

>>> num3 = int(input("Please input a decimal number:")

On this line of code you put it as the user input will be transferred to an int when in reality it should be a decimal float so we can round it later in the program. so it should be:

>>> num3 = float(input("Insert a decimal: "))

Second Line of code:

>>> num3 = int(round(num3, 2))

In this case, the int() function is not needed. so just remove and its good.

Lastly you used:

>>> print("your rounded decimal is: ", x)

Which is perfectly fine. Two more ways to output the same thing is by using:

>>> print(f"You rounded decimal is: {num3}")

Or just use the format() string method:

>> print("You rounded decimal is: {0}", num3)

Q&A Education