Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
lukerucker
1,754 PointsQuestion on a simple program
Hi again! I asked a question yesterday on how to write a program that solves simple algebra equations i.e. x + 6 = 12. So I've been trying to write the different parts of it in different programs so that I can work out how to do each thing. So right now I've been working on the part that figures out if a string is an integer and if it is then convert it into an int() or float(). Here is what I've gotten so far:
running = True
while running:
test = raw_input('Enter something: ')
if str.isdigit(test):
float(test)
test = test + 1
print test
running = False
else:
print 'Please enter a valid number.'
continue
'''
And when I run it I get the error:
'''
Luke$ python test.py
Enter something: 5
Traceback (most recent call last):
File "test.py", line 7, in <module>
test = test + 1
TypeError: cannot concatenate 'str' and 'int' objects
Please help!
2 Answers
Kenneth Love
Treehouse Guest TeacherThe line float(test) doesn't turn test into a float, it just gives you a float version of test. You need to assign that to a variable.
lukerucker
1,754 PointsOk thanks!