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 trialKarrerah White
10,118 PointsWorking 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
6,521 PointsShort 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.
Tara Edwards
6,521 PointsNo problem
Karrerah White
10,118 PointsKarrerah White
10,118 PointsThat solved the issue right away. * instead of the + that was a tricky one. I will remember that. Thank you so much Tara!