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 trialsadik salad
1,916 Pointsam getting error even tho my scripts its similar to the teacher one
File "string.py", line 3, in <module>
print(input_String+int(input_int))
TypeError: Can't convert 'int' object to str implicitly
5 Answers
Misha Shaposhnikov
8,718 PointsDon't use the int() function on "input_int" because this returns an integer which you are trying to directly concatenate with input_String and Python can't do that. Since input_int is already a string since that is what the input() function returns, you can just do this:
print(input_String + input_int)
Happy Coding! =)
Hannah McFarlane
2,810 PointsI got the same error as sadik's when I ran my code. I think I made the same mistake: used the +
operator instead of a *
.
My solution was changing my print line to
print(input_string*int(input_int))
This worked. (and I put my glasses on after that.)
Misha's example I think would return Hello3
rather than the HelloHelloHello
you'd be after.
Godswill Utionkpan
985 PointsMisha Shaposhnikov sadik salad Thanks!
wei du
2,569 Pointsso I have a different issue:
below is my code:
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))
and I can run through the first part fine, until I need to put in an integer , then here is the message I received: name 'input_string' is not defined.
The only thing I can see differently when I type the code in the workspace is the * (shift + 8) sign, when the video type in the sign, it turned to orange color, however, when I did it, the sign did not turn...
anyone can check my code please?
thanks
Wei
wei du
2,569 Pointsnever mind, I find out my problems: I need to type in space behind the input_string and input_int.
Kat Vieux
424 PointsI also had this issue. My code was correct but for some reason it didn't work without a linebreak between the first and second input strings. (hope I said that right...)
Mohammad Ferooz Ahad
358 Pointsthere is no plus sign it is a star
print(input_string*int(input_int))