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 (2015) Logic in Python Print "hi"

i dont know whats wrong in this logic

how do i multiply strings with integers?

4 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 67,989 Points

It's as simple as:

string = 'Hi ' * 5

The 5 would be replaced by the argument count inside a function

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Sahil;

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's code passes - the code from the other people who answered does not.