Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Basics (Retired) Things That Count Basic Numbers

Working with ints and floats in python

Hi guys I'm working on the ints and floats section of python with Kenneth Love. In one of his examples under "the things that count section, Basic numbers video" he is using the print function to print the input string + the int version of input in. the code was as follows...

input_string = input("what string do you want to use? ") input_int = input("How many times should I repeat it? ")

print(input_string+Int(input_int))

I thought this code should repeat the int or whole number but instead I keep getting an error message that reads... TypeError : Can ’t convert ‘int’ object to str implicitly.

I dont understand why this code won't take. Anyone else having an issue with this?

2 Answers

Tara Edwards
Tara Edwards
6,521 Points

Short answer: You should put in

print(input_string*int(input_int)).  

The code has a "+" rather than a "*". So the interpreter assumes that you are joining variables together. Since Python can only join variables of the same type (string with string, list with list), the programmer gets an error message.

"*" is used as a multiplication operator in this sense. The interpreter gets "print this string this many times".

I hope that helps.

That solved the issue right away. * instead of the + that was a tricky one. I will remember that. Thank you so much Tara!