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 trial

Python Python Basics (2015) Logic in Python Print "hi"

Christopher Parke
Christopher Parke
21,978 Points

You're asking me to do something that wasn't taught in the tutorial. That's so annoying.

you tell me how to print a function once. cool. Now you ask me to print it multiple times. I have no idea what the syntax is. You never taught that. The only hint is "you can multiply strings by ints" Whatever that means.

printer.py

1 Answer

Tobias Helmrich
Tobias Helmrich
31,603 Points

Hey Christopher,

a string is a sequence of characters and you can define a string in Python by writing it in quotes.

In this example

greeting = "Hello"

greeting would be a string. Ints is the short term for integers and an integer is a whole number. And in Python you can simply multiply a string with an integer so if you write something like

greeting = "Hello"
print(greeting * 5)

it will print out "Hello" five times. When we apply this to the challenge where we put this in the function it will look like this:

def printer(count):
  print("Hi " * count)

I hope that helps and if you have further questions feel free to ask and don't get frustrated, good luck! :)