Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.


+7 votes

the round function worked well for questions 1&2. Why isn't it working on the question where we have to find the distance between two points?
Edit: I made a mistake, I meant to ask about number 2 instead of three. number three and one work fine. When I tried running my code on Thonny, it says TypeError: type complex doesn't define round method.

asked in CSC201 Spring 2021 by (1 point)
edited by

5 Answers

+4 votes

Have you tried to convert input funtion into float number?

variable = float(input('words'))

Because round() function will produce a float output as well.

Besides, the ways to make round() function works:

round(number or number variable, numberdigits)

Following the 3rd question, it would be:

print round(hypotenuse,2)


print('A right triangle has hypotenuse', round(hypotenuse,2))

answered by (1 point)
+3 votes

make sure your first argument is in parenthesis. so it should look like

round((equation for distance), number of decimals to round to)

if that doesn't help, could you be more specific about whats going wrong with the function?

answered by (1 point)
+3 votes

On q3, this happen might because you write the equation wrong or you didn't write the round() correctly

To round it to how many numbers after the decimal you want, you type

round(_the number/answer from anywhere__,__how many decimals you want__)

Positive means that that's how many decimal numbers to the right and negative means they round up digits, tenths, and hundred bases on how many you want to round up.

Hope this helps

answered by (1 point)
+3 votes

The same thing happened to me. The reason why it's not working is that you placed the round function for the line where the distance is being calculated. Try and place it on the print statement before distance. Like this, print("............", round(distance, number of decimal places))

answered by (1 point)
+1 vote

Try converting the input into float number and also place the round function in the print statement. That will work!!

answered by (1 point)