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 trialsahil jagdale
Courses Plus Student 1,043 Pointsi dont know whats wrong in this logic
how do i multiply strings with integers?
4 Answers
Chris Freeman
Treehouse Moderator 68,454 PointsIt's as simple as:
string = 'Hi ' * 5
The 5 would be replaced by the argument count
inside a function
Ken Alger
Treehouse TeacherSahil;
First, let me say "Welcome to Treehouse!"
Typically when you want to ask a code related question in the forum it helps if you post the code you are using, even if it doesn't work, so that others can see how you are attempting to solve the issue.
To your question though, in Python you can multiply strings and integers by doing string_value * integer_value
and that will return the string_value
, integer_value
times. For example:
def print_hi(count):
print("Hi " * count)
print_hi(5)
Would yield: Hi Hi Hi Hi Hi
Post back if you still have questions.
Happy coding,
Ken
Brendan Whiting
Front End Web Development Techdegree Graduate 84,738 Points"Hi"*4 would be "HiHiHiHi". That's what they mean by multiplying a string.
def printer(count):
print("Hi"*count)
james white
78,399 PointsBrendan's code passes - the code from the other people who answered does not.