0

I've looked at many similar issues but cannot find an answer so I'm hoping you guys can help me. I keep getting that TypeError message but have no idea why. Any advice would be greatly appreciated.

number = raw_input("Enter a number to be rounded: ")

decimallocation = number.find('.')
right = number[decimallocation:]    
greater = int(number+right+1)
lesser = int(number+right)

if right >= .5:
    print (greater)
else:
    print (lesser)
1
  • Looks like your right is a string, so it can't be compared with a float. Perhaps do if float(right) >= .5:. Commented Dec 4, 2012 at 3:42

2 Answers 2

1

The error is this line:

greater = int(number+right+1)

I think what you are trying to do is:

greater = int(number+right) + 1

One more possible error is in checking:

right > .5

where right is a str but .5 is not

Sign up to request clarification or add additional context in comments.

Comments

0

You need:

greater=int(int(number)+int(right)+1)
lesser=int(int(number)+int(right))

You need to make sure everything you are adding is an int or a str, you cant add both types together.

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.